From: Trans Date: 2005-09-23T12:31:41+09:00 Subject: Re: Inspect, looking in from the outside Florian Gro� wrote: > Trans wrote: > > > I've been thinking about accessing > > certain "metainfo" about an object from the outside rather then from > > the inside to ensure certain results. A friend say it goes against the > > grain of OOP and polymorphism, but I wonder if certian "metainfo" > > shouldn't? What do others think? > > I dunno, I've been fine with Object.instance_method(:inspect).bind(obj) > so far -- sure, you can wrap it in a module for convenience, but is it > really done that frequently? Ah! You are right. Though writing this out is way too long if you do use it more then a few times --which I am. Nonetheless I've worked out another way of dealing with it which wraps it up nicely, so it's no bother. require 'mega/blankslate' class Object class Inspector < BlankSlate def initialize( obj ) @obj = obj end def method_missing( sym, *args, &blk ) Object.instance_method( sym ).bind(@obj).call(*args, &blk ) end end def instance @_inspector ||= Inspector.new(self) end end It would be nice if there could be a module/class method version, as this still resides in the instance method namespace, but such is not as strightfoward. Anyway one point of entry in the instance space is manageable, I guess. Any additional suggestions? :) Thanks! T.