[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

prettyprint or pp questions

Hal E. Fulton

11/25/2004 11:37:00 AM

There are three things I would like to do but I am not
sure how:

1. Redirect the output to another IO -- something like

STDERR.pp obj

2. Retrieve the text without printing it (analogous to #inspect):

str = obj.pretty # or whatever

3. Add pp functionality to the Date class. This doesn't work:

class Date
def pretty_print
inspect
end
end


Thanks for assistance...

Hal



3 Answers

ts

11/25/2004 11:55:00 AM

0

>>>>> "H" == Hal Fulton <hal9000@hypermetrics.com> writes:

H> 1. Redirect the output to another IO -- something like
H> STDERR.pp obj

PP.pp(obj, STDERR) # or change $>


H> 2. Retrieve the text without printing it (analogous to #inspect):
H> str = obj.pretty # or whatever

str = ""; PP.pp(obj, str)


H> 3. Add pp functionality to the Date class. This doesn't work:

H> class Date
H> def pretty_print(obj)
H> inspect

obj.pp(inspect)

H> end
H> end


Guy Decoux





Gavin Sinclair

11/25/2004 12:59:00 PM

0

On Thursday, November 25, 2004, 10:37:16 PM, Hal wrote:

> There are three things I would like to do but I am not
> sure how:

> 2. Retrieve the text without printing it (analogous to #inspect):

> str = obj.pretty # or whatever

require 'extensions/object'
str = obj.pp_s

> 1. Redirect the output to another IO -- something like

> STDERR.pp obj

STDERR.puts obj.pp_s

Cheers,
Gavin

P.S. It seems to me that all the questions you're asking should be
more elegantly solved by the 'pp' library. That it, it should all
"just work".





Hal E. Fulton

11/26/2004 4:20:00 PM

0

ts wrote:
>>>>>>"H" == Hal Fulton <hal9000@hypermetrics.com> writes:

[snip solutions]


Merci beaucoups, M'sieur Decoux...


Hal