"Martin Pirker" <crf / sbox.tu-graz.ac.at> schrieb im Newsbeitrag news:41176b8e$0$18044$3b214f66 / aconews.univie.ac.at... > On implementing a state machine I'm stuck at... > > > h = Hash::new > h["func1"] = "Outer::Inner::dothis" > h["func2"] = "whatever" > > def whatever(x) > puts "whatever happens #{x}" > end > > module Outer > module Inner > def dothis(c) > puts "I did it #{c} times" > end > module_function :dothis > end > end > > Outer::Inner::dothis(3) > __send__(h["func2"],9) > __send__(h["func1"],7) > > === cut here === > > $ ruby ztrick.rb > > I did it 3 times > whatever happens 9 > ztrick.rb:21:in '__send__': undefined method 'Outer::Inner::dothis' for main:Object (NoMethodError) > from ztest.rb:21 > > > > local calls look ok - how to do dynamic calls across module/class boundaries? > consider the hash mostly populated first and the functions are defined later > (or never at all) > I'm not even sure whether this is a syntax or missunderstanding issue :-/ Misunderstanding I guess: __send__ without an instance sends to self, which in this case != Outer::Inner. So for the general case you need also need the instance that the message should be sent to. Try this: h = Hash::new h["func1"] = Outer::Inner.method :dothis h["func2"] = method :whatever def whatever(x) puts "whatever happens #{x}" end module Outer module Inner def dothis(c) puts "I did it #{c} times" end module_function :dothis end end Outer::Inner::dothis(3) h["func2"].call 9 h["func1"].call 7 Regards robert