[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: #p is to #inspect as #pp is to ?

Daniel Sheppard

11/30/2007 6:17:00 AM

=20
> I have this as a lone method, but it seems to me there should already
> be a way to do this with the 'pp' lib. (If not perhaps we could add
> it?)

I believe that pp calls Object#pretty_print - the source will tell you
more.

Dan.

4 Answers

Michael Fellinger

11/30/2007 7:01:00 AM

0

On Nov 30, 2007 3:17 PM, Daniel Sheppard <daniels@pronto.com.au> wrote:
>
> > I have this as a lone method, but it seems to me there should already
> > be a way to do this with the 'pp' lib. (If not perhaps we could add
> > it?)
>
> I believe that pp calls Object#pretty_print - the source will tell you
> more.

At least since 1.8.6 that method exists.

>
> Dan.

Trans

11/30/2007 7:17:00 AM

0



On Nov 30, 1:17 am, "Daniel Sheppard" <dani...@pronto.com.au> wrote:
> > I have this as a lone method, but it seems to me there should already
> > be a way to do this with the 'pp' lib. (If not perhaps we could add
> > it?)
>
> I believe that pp calls Object#pretty_print - the source will tell you
> more.

I looked at that and didn't see how that would help. As it says...

"To define your customized pretty printing function for your classes,
redefine a method pretty_print(pp) in the class. It takes an argument
pp which is an instance of the class PP. The method should use
PP#text, PP#breakable, PP#nest, PP#group and PP#pp to print the
object."

Don't see off-hand how that can help easily get a string of what it
would output.

Thanks,
T.

Michael Fellinger

11/30/2007 7:59:00 AM

0

On Nov 30, 2007 4:17 PM, Trans <transfire@gmail.com> wrote:
>
>
>
> On Nov 30, 1:17 am, "Daniel Sheppard" <dani...@pronto.com.au> wrote:
> > > I have this as a lone method, but it seems to me there should already
> > > be a way to do this with the 'pp' lib. (If not perhaps we could add
> > > it?)
> >
> > I believe that pp calls Object#pretty_print - the source will tell you
> > more.
>
> I looked at that and didn't see how that would help. As it says...
>
> "To define your customized pretty printing function for your classes,
> redefine a method pretty_print(pp) in the class. It takes an argument
> pp which is an instance of the class PP. The method should use
> PP#text, PP#breakable, PP#nest, PP#group and PP#pp to print the
> object."
>
> Don't see off-hand how that can help easily get a string of what it
> would output.

Sorry, i had the wrong method in mind, what you want is most likely
Object#pretty_inspect
Example:
puts (1..30).to_a.pretty_inspect

Does that help?

^ manveru

Trans

11/30/2007 12:38:00 PM

0



On Nov 30, 2:58 am, "Michael Fellinger" <m.fellin...@gmail.com> wrote:
> On Nov 30, 2007 4:17 PM, Trans <transf...@gmail.com> wrote:
>
>
>
>
>
> > On Nov 30, 1:17 am, "Daniel Sheppard" <dani...@pronto.com.au> wrote:
> > > > I have this as a lone method, but it seems to me there should already
> > > > be a way to do this with the 'pp' lib. (If not perhaps we could add
> > > > it?)
>
> > > I believe that pp calls Object#pretty_print - the source will tell you
> > > more.
>
> > I looked at that and didn't see how that would help. As it says...
>
> > "To define your customized pretty printing function for your classes,
> > redefine a method pretty_print(pp) in the class. It takes an argument
> > pp which is an instance of the class PP. The method should use
> > PP#text, PP#breakable, PP#nest, PP#group and PP#pp to print the
> > object."
>
> > Don't see off-hand how that can help easily get a string of what it
> > would output.
>
> Sorry, i had the wrong method in mind, what you want is most likely
> Object#pretty_inspect
> Example:
> puts (1..30).to_a.pretty_inspect
>
> Does that help?

w00t! w00t!

thanks manveru!

T.