From: Jarmo Pertman on 28 Jun 2010 09:02 Hello! Idea would be to write contents of some objects into some file in pretty inspection format. How is it possible in Ruby to get pretty inspection of an object without printing it to stdout? One possibility would be to play with stdout redirection while using 'pp', but that's not what i'm looking for. Is there any easy way to do it or should i start monkey-patching 'pp' to add that feature? Jarmo -- Posted via http://www.ruby-forum.com/.
From: Brian Candler on 28 Jun 2010 09:18 Jarmo Pertman wrote: > Idea would be to write contents of some objects into some file in pretty > inspection format. > > How is it possible in Ruby to get pretty inspection of an object without > printing it to stdout? > > One possibility would be to play with stdout redirection while using > 'pp', but that's not what i'm looking for. Is there any easy way to do > it or should i start monkey-patching 'pp' to add that feature? Why monkey-patch? Look at source of pp.rb, and you'll see it takes an optional argument, out=$> require 'pp' a = {:foo=>1,:bar=>2} File.open("/tmp/pp.out","w") { |f| PP.pp(a, f) } -- Posted via http://www.ruby-forum.com/.
From: Jarmo Pertman on 28 Jun 2010 10:59 Richard Conroy wrote: > On Mon, Jun 28, 2010 at 2:02 PM, Jarmo Pertman <jarmo.p(a)gmail.com> > wrote: > >> it or should i start monkey-patching 'pp' to add that feature? >> >> > You might want to have a look at awesome print - a gem that is a > functional > replacement for pretty print. Thank you for the answers! I also noticed that there is a #pretty_inspect method after requiring 'pp': a.pretty_inspect does exactly the thing i want - returns a string. I'll look at that awesome print gem also :) Jarmo -- Posted via http://www.ruby-forum.com/.
|
Pages: 1 Prev: passing a block to yield Next: Looking to generate MS Doc files |