From: "Ara.T.Howard" Date: 2004-05-25T09:53:45+09:00 Subject: Re: How to pp-enable a class? 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 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 -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | URL :: http://www.ngdc.noaa.gov/stp/ | "640K ought to be enough for anybody." - Bill Gates, 1981 ===============================================================================