0

I'm wondering if it's possible to start a Byebug session giving a starting point from a Rails console. I know I can insert a byebug statement wherever I want and start debugging, but I'd like to do something like this:

Byebug.start do
  # entry point
  User.find(12).problematic_method
end

Thanks.

oxfist
  • 749
  • 6
  • 22
Matias
  • 575
  • 5
  • 17
  • What would that code do? Where should it stop? When loading `User` class? When doing `User.find`? When doing `problematic_method`? if the latter, how byebug would know to not stop at earlier steps? :) – Sergio Tulentsev Oct 24 '17 at 12:39
  • 1
    If you want to debug `problematic_method`, you could call `byebug` from within that method. – Stefan Oct 24 '17 at 12:44
  • 1
    @SergioTulentsev yes, I also thought that, but maybe starting the session before any call and let me step into. But this could be a nightmare too. – Matias Oct 24 '17 at 13:22

2 Answers2

1

I opened the class and override the problematic_method inside the Rails console and added the byebug statement where I wanted it. This way I don't have to change the running production code (I forgot to mention above I want to debug in production).

This workaround will be enough for my purposes. The only problem is that you don't have the debug code listing available for that method, but its fine.

oxfist
  • 749
  • 6
  • 22
Matias
  • 575
  • 5
  • 17
0

That is not possible. What you can do, is write your code inside a .rb file and debug that file/script using byebug.

Holger Frohloff
  • 1,695
  • 18
  • 29