Is it possible to debug dynamically defined method in Ruby? If so, how can I achieve it?
So I opened a new Pry session and first tried it like this:
require "byebug"
def hello(x)
byebug
x += 1
puts x
end
hello(5)
It shouted at me with "*** No sourcefile available for (pry)". I was still able to step through the code, but I couldn't see the source.
Then I tried doing it like this:
def hello(x)
binding.pry
x += 1
puts x
end
hello(5)
And now it's the other way round: I am able to see the source code, but I can't step through the code (when I type "step" it shouts at me with "NameError: undefined local variable or method `step' for main:Object"). Looks like Pry actually does have the needed source, but the debugger doesn't work unfortunately :(
I managed to do it in Python repl using IPython (It didn't work in standard Python repl though):
def hello(x):
breakpoint()
x += 1
print(x)
hello(5)
I would love to be able to achieve the same in Ruby