From: Sam Roberts Date: 2005-03-08T11:24:49+09:00 Subject: Re: implementing #to_pp, and pp.rb doc diffs (Re: Requesting addition to IRB (configurable standard output)) Quoting akr@m17n.org, on Sun, Mar 06, 2005 at 11:58:34AM +0900: > In article <20050226025441.GA17581@ensemble.local>, > Sam Roberts writes: > > > Even after converting the docs to rdoc format, I see no simpler way. > > Thank you for the rdocification. It is merged. Great, thanks. > I'm not sure that to_pp is a name good enough for Kernel. I agree. That code came from my .irbrc file, I wanted something short. I think the functionality is useful, and it was not so obvious to me how to implement it. Maybe use a different name? Or maybe just document how to do this with sample code? Sam Index: pp.rb =================================================================== RCS file: /src/ruby/lib/pp.rb,v retrieving revision 1.27.2.13 diff -u -r1.27.2.13 pp.rb --- pp.rb 6 Mar 2005 02:57:53 -0000 1.27.2.13 +++ pp.rb 8 Mar 2005 02:22:06 -0000 @@ -274,6 +274,17 @@ # # However, doing this requires that every class that #inspect is called on # implement #pretty_print, or a RuntimeError will be raised. + # + # If you just want a simple way to get the string representation for an Object + # in the same format #pp prints it, it is possible to do something like: + # module Kernel + # def pp_str + # s = PP.pp(self, '') + # s.chomp! + # s + # end + # end + # This can be useful when it is put in your ~/.irbrc file, for example. def pretty_print_inspect if /\(PP::ObjectMixin\)#/ =~ method(:pretty_print).inspect raise "pretty_print is not overridden."