Quick debugger tip in Ruby

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.

About these ads

One response to “Quick debugger tip in Ruby

  1. Use Lisp and breaking into the debugger is automatic

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s