Max Williams
2007-Oct-29 17:22 UTC
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Max Williams
2007-Oct-29 18:09 UTC
Re: pretty-printing (or otherwise) a hash in a view template
Max Williams 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! > maxI 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
James Moore
2007-Oct-29 20:29 UTC
Re: pretty-printing (or otherwise) a hash in a view template
On 10/29/07, Max Williams <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 Moore | james-7AXNjMB9LsNl57MIdRCFDg@public.gmane.org Ruby and Ruby on Rails consulting blog.restphone.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Max Williams
2007-Oct-30 10:46 UTC
Re: pretty-printing (or otherwise) a hash in a view template
James Moore wrote:> On 10/29/07, Max Williams <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 Moore | james-7AXNjMB9LsNl57MIdRCFDg@public.gmane.org > Ruby and Ruby on Rails consulting > blog.restphone.comThat''s not what i''m after, though i agree that yaml is nice and readable. thanks anyway. :) In addition to PP.pp(myhash, ""), btw, i discovered that myhash.inspect also works. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---