Pretty-printing (or otherwise) a hash in a view template

I have some text boxes into which i want to output the contents of some
hashes, in the nice readable way we all know and love. Can i use
pretty-print for this? As far as i can tell, pp only works to standard
output and can’t be used to create text.

Is there another way to nicely print out the contents of a hash?

thanks!
max

Max W. wrote:

I have some text boxes into which i want to output the contents of some
hashes, in the nice readable way we all know and love. Can i use
pretty-print for this? As far as i can tell, pp only works to standard
output and can’t be used to create text.

Is there another way to nicely print out the contents of a hash?

thanks!
max

I actually found out how to do this from another post somewhere - you
can get the output of pp into a string with

text = PP.pp(myhash, “”)

The resultant string has any quotes inside it escaped out.

thanks

On 10/29/07, Max W. [email protected] wrote:

Is there another way to nicely print out the contents of a hash?

Give to_yaml a shot. It’s a very readable way to dump ruby objects.


James M. | [email protected]
Ruby and Ruby on Rails consulting
blog.restphone.com

James M. wrote:

On 10/29/07, Max W. [email protected] wrote:

Is there another way to nicely print out the contents of a hash?

Give to_yaml a shot. It’s a very readable way to dump ruby objects.


James M. | [email protected]
Ruby and Ruby on Rails consulting
blog.restphone.com

That’s not what i’m after, though i agree that yaml is nice and
readable. thanks anyway. :slight_smile:

In addition to PP.pp(myhash, “”), btw, i discovered that myhash.inspect
also works.