From: Mike Gold Date: 2009-02-11T10:02:59+09:00 Subject: Re: calling class method from instance .. Larz wrote: > > def itest > puts @i > # here's what I was trying to do !!! > puts self.class.ctest > end I think Object#class is something to be avoided in most cases. Frankly it's none of your business what class was used to create an object. It doesn't matter _how_ an object sprang into existence, what matters is how it quacks. I want to replace an object with a delegate with no ill effects. Or with a mock object, or with whatever. But uses of Object#class defeat this. I would be inclined to make shared data explicit either with a constant or a with a passed-in reference to the shared data, rather than implicit with Object#class. class Test SHARED = Struct.new(:ctest).new(2) def itest puts SHARED.ctest end end Test.new.itest #=> 2 -- Posted via http://www.ruby-forum.com/.