Coding with a purpose

Quick debugger tip in Ruby

31 January, 2009 · 1 Comment

The ruby-debug gem is great for debugging but here’s something you might have missed: you can call it with a condition. That way it only breaks execution when a given condition is met.


[3, 2, 15, nil, 5].collect do |id|

  debugger if id.nil?

  id.to_s

end

That way, it will only stop if one of the array items is nil. This is a huge time-saver. Use it frequently.

Categories: Uncategorized

1 response so far ↓

Leave a Comment