From: Robert Klemme Date: 2005-04-17T00:49:35+09:00 Subject: Re: self "Trans" schrieb im Newsbeitrag news:1113654704.368730.203380@l41g2000cwc.googlegroups.com... > > 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) Of course not - cause I *knew* that it does not work. But if that comforts you >> class MySuperClass >> def self.do_something >> puts "success" >> end >> end => nil >> ?> class MyClass < MySuperClass >> do_something >> end success => nil >> Oooops... :-))) Looks like it's rather me that has to go back to school. Now *you* explain why it works. >> 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. But apparently superfluous >> class My2 < MyClass >> do_something >> end success => nil Could it be that this didn't work in older versions? I'm almost sure that I did try this once and it failed. This is strange... Thanks for crushing my certainty! Kind regards robert