From: Tom Cloyd Date: 2009-04-19T00:46:28+09:00 Subject: Re: simple module method call question Suraj Kurapati wrote: > James Coglan wrote: > >> You've defined an instance method, not a module method. The method as >> you define it will appear in classes that use 'include Utils'. To get a >> module method, define it on self: >> >> module Utils >> MENU = [ ... ] >> >> def self.orph_chk >> # ... >> end >> end >> > > Alternatively, you could use module_function() to make the instance > method a class method on the module: > > module Utils > def orph_chk > # ... > end > > module_function :orph_chk > end > > > Now you can either call the method directly (Utils.orph_chk) or mix it > in (include Utils; orph_chk). So you can have your cake and eat it too! > Hmmm. This is most interesting. Ruby amazes me every day. So much built-in cleverness. And now this, which I've never seen anywhere. I'll study up on it. Thanks very much for the heads up, Tom -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist Bellingham, Washington, U.S.A: (360) 920-1226 << tc@tomcloyd.com >> (email) << TomCloyd.com >> (website) << sleightmind.wordpress.com >> (mental health weblog) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~