Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(undefined local variable or method `byebug'

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!

like image 292
TGI Avatar asked Oct 15 '14 20:10

TGI


People also ask

Why do I get undefined local variable error in Ruby?

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.

How do you print the value of variables in byebug?

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).

What is the difference between byebug and debugger?

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.

What is the difference between byebug and pry-byebug?

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.


2 Answers

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.

like image 128
tuxayo Avatar answered Oct 06 '22 01:10

tuxayo


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

like image 30
Calin Ciobanu Avatar answered Oct 06 '22 00:10

Calin Ciobanu