Say I have a loop in my code that calls the rails debugger a few times
def show
animals = [\'dog\', \'cat\', \'owl\', \'tiger\']
for animal in animals
I have another answer to this one: set a @debug
on the class that you want to debug. That way you can do:
if (@debug && (the_condition)) then debugger end
or
debugger unless !@debug
then when you are done with the debugger just @debug = false
and c
.
However, I'm not really happy with having debugger 'hard stops' in live code. These are the kind of things that can be accidentally checked in and forgotten about until something breaks. The @debug
would certainly fall under that as well. To that end I think my ideal solution would use Matt's idea and a script that sets up a breakpoint inside the object when the object is created. That way you'd have the debugging that you want but you wouldn't have any code in source control that is specifically for development. I'll update this answer if I find such a solution.