From: Charles Mills Date: 2004-12-02T05:55:28+09:00 Subject: Re: to_s, inspect, etc. On Dec 1, 2004, at 12:27 PM, itsme213 wrote: > It sounds from the discussion that we could benefit from a well > thought out > (and/or well described!) framework for a set of print-related methods. > I > know consistent use of these would help _me_ a lot. > > A naive (and incomplete and incorrect) example. Any resemblance to > real Ruby > methods is purely accidental. > > - #short: a context-insensitive short string (no newlines) identifying > the > object + class what about just using to_s "#>1>" > - #probe: 1-level deep object structure + #short descriptions of 2nd > level, > single line > - #probe n: N-level deep object structure > - #probe n Filter: N-level deep object structure only showing elements > of > Filter These could be useful for some sort of graphing package (showing object graphs) / object browser. > - #inspect: show full recursive object structure, ending at [String, > Symbol, > Int, ...] > - #identify should show short string for object identification e.g. > just a > 'name' attribute > - Object#short by default will print class name + #to_s > - #to_s should .... > - Object#inspect by default will .... > I think the current framework (#to_s and #inspect) does the job... seems like this would create extra work for developers and muck up the name space. It is probably enough to just override Object#inspect in really complicated classes (if someone else is going to be using them). -Charlie