# \#p is to #inspect as #pp is to?

**URL:** https://rubytalk.org/t/p-is-to-inspect-as-pp-is-to/42628
**Category:** ruby-talk
**Created:** [30 November 2007 06:17 UTC](https://rubytalk.org/t/p-is-to-inspect-as-pp-is-to/42628 "2007-11-30T06:17:21Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Daniel\_Sheppard](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@Daniel\_Sheppard](https://rubytalk.org/u/Daniel_Sheppard)
#### Post date: [30 November 2007 06:17 UTC](https://rubytalk.org/t/p-is-to-inspect-as-pp-is-to/42628/1 "2007-11-30T06:17:21Z")

</div>

> 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.

---

<div class="post-metadata">

### Author: ![Michael\_Fellinger1](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@Michael\_Fellinger1](https://rubytalk.org/u/Michael_Fellinger1)
#### Post date: [30 November 2007 07:01 UTC](https://rubytalk.org/t/p-is-to-inspect-as-pp-is-to/42628/2 "2007-11-30T07:01:20Z")

</div>

> \> 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.

> **···**
>
> On Nov 30, 2007 3:17 PM, Daniel Sheppard \<daniels@pronto.com.au\> wrote:
> 
> > Dan.

---

<div class="post-metadata">

### Author: ![7rans](https://avatars.discourse-cdn.com/v4/letter/7/a8b319/32.png) [@7rans](https://rubytalk.org/u/7rans)
#### Post date: [30 November 2007 07:17 UTC](https://rubytalk.org/t/p-is-to-inspect-as-pp-is-to/42628/3 "2007-11-30T07:17:07Z")

</div>

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.

> **···**
>
> 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.

---

<div class="post-metadata">

### Author: ![Michael\_Fellinger1](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@Michael\_Fellinger1](https://rubytalk.org/u/Michael_Fellinger1)
#### Post date: [30 November 2007 07:58 UTC](https://rubytalk.org/t/p-is-to-inspect-as-pp-is-to/42628/4 "2007-11-30T07:58:34Z")

</div>

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

> **···**
>
> 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.

---

<div class="post-metadata">

### Author: ![7rans](https://avatars.discourse-cdn.com/v4/letter/7/a8b319/32.png) [@7rans](https://rubytalk.org/u/7rans)
#### Post date: [30 November 2007 12:38 UTC](https://rubytalk.org/t/p-is-to-inspect-as-pp-is-to/42628/5 "2007-11-30T12:38:11Z")

</div>

w00t! w00t!

thanks manveru!

T.

> **···**
>
> 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?
