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 :-/
any hints on how to do a fast state machine appreciated
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:
ztrick.rb:21:in '__send__': undefined method 'Outer::Inner::dothis' for main:Object (NoMethodError)
from ztest.rb:21
It does not work because send will only call a method of the object you call it on. Outer::Inter::dothis is not a method name, but the name of a module with a method name at the end.
But there is a way for it to work, just replace your __send__ with a call to my little smart_call:
def smart_call(name, *params)
array = name.split(/::/)
# array[0...-1] contains the modules list
# array[-1] contains the class name
array[0...-1].inject(Kernel) { |memo, obj| memo.const_get(obj) }.send(array[-1], *params)
end
I'm sure it could be written in a better way, but I am not a pro in Ruby ^o^
It just gets the wanted module (using const_get) and calls the method on it.