prettyprint or pp questions

H

Hal Fulton

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
 
T

ts

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
 
G

Gavin Sinclair

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top