Printing the contents of variables to the screen legibly

Hi there,

I am a recent convert from PHP, specifically CakePHP. When I would run
a query in CakePHP and read that query into an array, I could run a
function debug() on that array and it would print all of the contents
of that array very neatly on the screen. If I run a query like @order
= Order.find(1), it reads all of the order information as well as the
related line_items information into the @order variable, but when i
run @order.inspect I can only see the order information (and not the
associated line_items) and it also reads it out in one long string
instead of each hashed value on a new line etc.. Is there a better
method than inspect to print the contents of a variable more legibly
to the screen?

Thanks!

Rails also has a debug() function. Not sure if that'd get you child
elements automatically tho...

Rails also has a debug() function. Not sure if that'd get you child
elements automatically tho...

debug is fine in a view, at the console pp (pretty print) is nice too
(you need to require 'pp' first)

Fred

validkeys wrote:
Is there a better

method than inspect to print the contents of a variable more legibly
to the screen?

If I'm in a view I use Rails' debug method. Everywhere else (including
the logger) I use object.to_yaml.

Works beautifully.

is there anyway to see the related information as well? Like a query
that returns a post and all related comments. Debug only seems to show
the post but not the comments.