I have the follwing error:
NameError (undefined local variable or method `byebug'
Code is
def test t = "" byebug end
--
RAILS_ENV=development gem list | grep bye
byebug (3.5.1)
then I run :
RAILS_ENV=development rails s
but it shows:
NameError (undefined local variable or method `byebug'
Do you have any idea why?
Thanks!
This is most often due to a typo but may happen when refactoring code and renaming variables. You might also see the "NameError: undefined local variable" Ruby error if you intended to enter a string. Strings are understood when they exist between quotes.
Now let us step through the program. The first step command runs the script one executable unit. The second command we entered was just hitting the return key: byebug remembers the last command you entered was step and runs it again. One way to print the values of variables is eval (there are other ways).
There used to be a gem called debugger in the Ruby ecosystem, which did for Rubies older than 2.0 what byebug does for us now. However, that gem has been long dead as the Ruby community has almost completely migrated to Ruby 2+. In Ruby 2, debugger was an alias for byebug that came with the byebug gem.
The only difference that remains is that with byebug, you get n, s, c etc as shortcut commands to execute next, step and continue, respectively. With binding.pry, pry-byebug disables these shortcuts as they might conflict with local variable names.
It seems you need to
require 'byebug'
I was in the same situation and require failed with 'cannot load such file' error but adding to the Gemfile worked.
Make sure you haven't installed the gems with bundle install --without development
option.
If that is the case just run bundle install --with development
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With