From: Tom Cloyd Date: 2009-04-17T23:39:32+09:00 Subject: Re: simple module method call question James Coglan wrote: >> This always fails. I've tried every trick I can think of, but always I get >> this: >> >> ../lib/setnet/SN.rb:579:in `proc_command': undefined method `orph_chk' for >> Utils:Module (NoMethodError) >> from ../lib/setnet/SN.rb:229:in `eval' >> from ../lib/setnet/SN.rb:579:in `proc_command' >> from ../lib/setnet/SN.rb:229:in `user_interface' >> from ../lib/setnet/SN.rb:146:in `manage' >> from ../lib/setnet/SN.rb:68:in `startup' >> from ./setnet:28 >> >> Can someone suggest why I'm not able to get to this method? >> >> Here's the relevant Module, in abbreviated form: >> >> module Utils >> >> MENU = [ >> ["orph_chk", "searches nodes and links for references which cannot be >> resolved, and reports them"], >> ["tree_count","starting with node 'root', locates descendants of each >> node, displaying count at each level"], >> ["showtree","starting with node 'root', locates and displays descendants >> of each node"], >> ["tree_orphans","locates links which cannot be traced to the root node, >> and displays them"] >> ] >> >> def orph_chk >> puts 'orph_chk' >> end >> >> end >> > > > > 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 > > -- > James Coglan > http://github.com/jcoglan > > Well. Live and learn. Very simple solution, but I sure wasn't looking in THAT corner of the universe. Thank you very much. t. -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~