Is there a print_r or var_dump equivalent in Ruby / Ruby on Rails?

I'm looking for a way to dump the structure of an object, similar to the PHP functions print_r and var_dump for debugging reasons.


The .inspect method of any object should format is correctly for display, just do..

<%= theobject.inspect %>

The .methods method may also be of use:

<%= theobject.methods.inspect %>

It may help to put that in <pre> tags, depending on the data


In views:

include DebugHelper

...your code...

debug(object)

In controllers, models, and other code:

puts YAML::dump(object)

Source