From: "Ara.T.Howard" Date: 2005-10-18T10:34:09+09:00 Subject: Re: Class method aliasing On Tue, 18 Oct 2005, Bob Hutchison wrote: > Hi, > > I'd like to confirm that I cannot use any kind of aliasing to tidy up the > following situation: > > class Junk > def Junk.info > "blah blah blah" > end > > def info > Junk.info > end > end > > I'd really like to be able to write the following: > > puts Junk.info > > # then somewhere far from there... > junk = Junk.new > puts junk.info > > I don't find junk.class.info satisfying, and if that were a module method, > then you have to know too much. > > I guess what I'm trying to do is make class/module methods directly available > to instances, and it seems I can't do that (whatever the reason). > > Any better ideas are more than welcome. > > Cheers, > Bob harp:~ > cat a.rb class Module def mod_attr a module_eval <<-code def #{ a } self::class.send '#{ a }' end def #{ a }= value self::class.send '#{ a }=', value end code end end class C def C::info 42 end mod_attr 'info' end p C::info p C::new.info harp:~ > ruby a.rb 42 42 -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | anything that contradicts experience and logic should be abandoned. | -- h.h. the 14th dalai lama ===============================================================================