Are there good docs or even a tutorial on how to enable a class
to be prettyprinted with pp?
It looks like the sort of thing I could figure out in 5 or 6 hours
of experimentation. I’d rather not spend those if I can help it.
I did read this link, which is a reference:
http://cvs.m17n.org/~akr/pp/pp.html
It contains among other things the tantalizing entry:
“To define your customized pretty printing function for your
class, 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.”
But I don’t grasp the details yet.
Hal
I’ve never expended any effort “preparing” a class for pp’ing. I just
pp it and am happy with the result.
Objects are just a recursive collection of objects and core types.
Core types have their pp defined, and objects are just structure. So
it should all Just Work.
Cheers,
Gavin
···
On Tuesday, May 25, 2004, 6:08:07 AM, Hal wrote:
Are there good docs or even a tutorial on how to enable a class
to be prettyprinted with pp?
It looks like the sort of thing I could figure out in 5 or 6 hours
of experimentation. I’d rather not spend those if I can help it.
Gavin Sinclair wrote:
Are there good docs or even a tutorial on how to enable a class
to be prettyprinted with pp?
It looks like the sort of thing I could figure out in 5 or 6 hours
of experimentation. I’d rather not spend those if I can help it.
I’ve never expended any effort “preparing” a class for pp’ing. I just
pp it and am happy with the result.
Objects are just a recursive collection of objects and core types.
Core types have their pp defined, and objects are just structure. So
it should all Just Work.
True in general.
But I have a case (hence my question) where it doesn’t “just work”
and I’m not sure why.
I can’t reproduce it simply yet, or I’d show you.
Hal
the other case where it does not work is in cases where you might want to use
#inspect, but do not because your object is not that pretty. here is an
example and my work around:
~ > cat a.rb
require ‘pp’
require ‘logger’
class Object
def pretty port = ‘’
PP::pp(self, port).strip
end
end
class Config < Hash; end
logger = Logger.new STDOUT
conf = Config[ ‘key’ => ‘value’ ]
logger.debug{ “conf <#{ conf.pretty }>” }
~ > ruby a.rb
D, [2004-05-24T17:42:13.811603 #23616] DEBUG – : conf <{“key”=>“value”}>
IMHO if you require ‘pp’ Object#pretty should be defined automatically.
cheers.
-a
···
On Tue, 25 May 2004, Hal Fulton wrote:
Gavin Sinclair wrote:
Are there good docs or even a tutorial on how to enable a class
to be prettyprinted with pp?
It looks like the sort of thing I could figure out in 5 or 6 hours
of experimentation. I’d rather not spend those if I can help it.
I’ve never expended any effort “preparing” a class for pp’ing. I just
pp it and am happy with the result.
Objects are just a recursive collection of objects and core types.
Core types have their pp defined, and objects are just structure. So
it should all Just Work.
True in general.
But I have a case (hence my question) where it doesn’t “just work”
and I’m not sure why.
I can’t reproduce it simply yet, or I’d show you.
Hal
–
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: Solar-Terrestrial Physics Data | NCEI
“640K ought to be enough for anybody.” - Bill Gates, 1981
===============================================================================