In Ruby, we have a gem called byebug and a gem called pry.
In pry, you can type whereami to see where you are, when you are in a binding.pry session.
How do you do the same thing in byebug?
Something similar to whereami in byebug is list https://fleeblewidget.co.uk/2014/05/byebug-cheatsheet/
you can also type help when in a byebug session to get the list of commands
Related
I've started to use Spacemacs and I have a trouble with ruby autocompletion. When Gemfile contains pry autocompletion works fine, but if pry is not present in the Gemfile, I get the error cannot load such file -- pry after :robe-start or SPC m s i. I don't want to add unnecessary gems to the Gemfile and looking for the solution to use globally installed pry.
I researched and found the next solutions: Add Pry.config.eager_load! to .pryrc or add pry to global gemset but any of them did not help.
I'm working with pry 0.10.1 java and pry-nav 0.2.4 on jruby 1.7.12 (1.9.3p392). In the middle of an rspec step after invoking binding.pry, I type the pry command:
whereami
All I get is
ArgumentError: Symbol or String expected, but NilClass given.
from /Users/yc98js1/.rbenv/versions/jruby-1.7.18/lib/ruby/gems/shared/gems/coderay-1.1.0/lib/coderay/helpers/plugin.rb:215:in `validate_id'
whereamI going wrong? [pun intended]
Seems like the error was thrown by the coderay gem. Could be a collision of this gem with another.
It might be unrelated but its hiding the error. try uninstalling coderay first and running the code again.
Ok, as #tim-moore asked, I will post it in new question.
Ok, so I wanted to make gem using bundle. Pry extension gem require that gem start with pry- as mentioned here.
I used:
bundle gem pry-name
but it messed up my file structure
create pry-name/pry-name.gemspec
create pry-name/lib/pry/name.rb
create pry-name/lib/pry/name/version.rb
As you can see it created lib/pry directory. I know it's gem's style to created such structure but now I pry cannot load this gem automatically
One solution from my question was:
create pry-name.rb that contain only require 'pry/name'
After I have done this, and build gem, I started pry:
This message appear:
require 'pry-name' # Failed, saying: Pry is not a module
As for my guesses:
I'm creating commands writing something like this:
Pry::Commands.create_command "name-of-command" do
# my code goes here
end
and, as ruby find Pry::Commands. it want require it from lib directory not from Pry gem.
What does this error mean. Why it doesn't work. How make it work keeping in mind gem and pry requirements(pry gem starts with pry- and gem will create another directory(ies) when someone use - for example: gem pry-name will make pry/name)
Everywhere in your newly-created gem where it has module Pry, change it to: class Pry. Since Pry is already defined (as a class), you cannot redefine/reopen it as a module.
I have a gem called "something".
I would like to add pry as a development dependency when developing the gem. However I don't know how to load it.
If I have "require something" inside lib/something.rb , when I release the gem, it throws a LoadError, because pry is only a development dependency.
At the same time I don't want to keep adding and removing pry when I am committing code.
What is the best way to require pry only when developing the application, but not require it as a dependency for the gem?
You can use the add_development_dependency in the gemspec file. You'll still have to require it in your lib/something.rb file within a begin .. rescue LoadError block. (Edit 2, see below)
In your case, it will be something like the following:
spec.add_development_dependency 'pry', '~> 0.9.12.2'
The purpose of add_development_dependency is to separate the gems into dependencies that get installed when you execute gem install mygem vs development-only dependencies that are installed only when you execute gem install mygem --development.
Edit: #Pierre-Louis Gottfrois' solution
Modify the Gemfile directly and add a test group. This question describes the process. This does not appear to be a preferred solution according to Yehuda Katz.
Edit 2: begin require ... rescue LoadError is apparently a common practice for Ruby scripts, according to this Making Ruby Gems article.
I think I found a workaround for that.
If you configure bundler to use pry as your console with
$ bundle config console pry
Then pry is itself required and you don't need to explicitly require in your source files.
Plus, you get a history on pressing ' ↑ '.
I want to use pry from within irb/debugger, so I can:
invoke step, next, continue, finish inside of pry
still be able to set breakpoints, etc.
What I did is the following:
$ gem install pry
$ gem install debugger
$ gem install debugger-pry
In the code I have inserted require 'debugger'; debugger
Then I start my program with ruby example, the irb promp starts and as described here it should display the pry command on help, but it does not.
ruby-debug help v1.5.0
...
(rdb:1) pry
*** Unknown command: "pry". Try "help".
Any idea how I could check whether it is installed correctly or what am I missing?
I think you need:
require 'debugger/pry'
you could add it to the top of your example.rb file.