From: Trans Date: 2005-04-16T22:04:34+09:00 Subject: Re: self Robert Klemme wrote: > "Trans" schrieb im Newsbeitrag > news:1113449849.596475.60490@z14g2000cwz.googlegroups.com... > > 1) use a superclass rather than a module: > > > > class MySuperClass > > def self.do_something > > puts "success" > > end > > end > > > > class MyClass < MySuperClass > > do_something > > end > > Did you verify that this works? :-) Of course not! :-) But if that doesn't work then I need go back to training wheels!!! Did you verify that is doesn't? if so then then again! ;o) > Here's what I do if I want to have a set of singleton methods available for > all classes in a class hierarchy: > > class Base > module MySpecialClassMethods > # make inheritance work: > def inherited(cl) cl.extend MySpecialClassMethods end > > attr_accessor :bar > def foo() "foo" end > # other methods... > end > > extend MySpecialClassMethods > end You're right, this is a great approach. T.