[#4595] New block syntax — Daniel Amelang <daniel.amelang@...>

I'm really sorry if this isn't the place to talk about this. I've

25 messages 2005/03/21
[#4606] Re: New block syntax — "David A. Black" <dblack@...> 2005/03/21

Hi --

[#4629] Re: New block syntax — "Sean E. Russell" <ser@...> 2005/03/30

On Monday 21 March 2005 16:17, David A. Black wrote:

[#4648] about REXML::Encoding — speakillof <speakillof@...>

Hi.

15 messages 2005/03/31
[#4659] Re: about REXML::Encoding — "Sean E. Russell" <ser@...> 2005/04/04

On Thursday 31 March 2005 09:44, speakillof wrote:

Re: implementing #to_pp, and pp.rb doc diffs (Re: Requesting addition to IRB (configurable standard output))

From: Sam Roberts <sroberts@...>
Date: 2005-03-08 02:24:49 UTC
List: ruby-core #4528
Quoting akr@m17n.org, on Sun, Mar 06, 2005 at 11:58:34AM +0900:
> In article <20050226025441.GA17581@ensemble.local>,
>   Sam Roberts <sroberts@uniserve.com> 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."


In This Thread

Prev Next