I have the following method_missing code implemented in a model:
# class Thought
def self.method_missing(method_id, *arguments, &block)
if $CLIENT.respond_to?(method_id)
$CLIENT.send(method_id, *arguments, &block)
# Do some stuff with it
else
super
end
end
$CLIENT is a global object. Note that this is method_missing for the class, not the instance.
I tried the following in script/console:
>> $CLIENT.respond_to?(:my_thoughts)
=> true
>> $CLIENT.send(:my_thoughts, 'bob', 5)
=> #<#<Class:01xe229be>:0x241391>
>> Thought.send(:my_thoughts, 'bob', 5)
ArgumentError: wrong # of arguments(1 for 2)
from [filepath]:50:in `method_missing'
from (irb):4
Is there something painfully obvious I’m missing here? I’m running this on Rails 2.3.8 and jRuby if that makes a difference.
Edit: This confuses me even more:
>> Thought.send(:my_thoughts, 'bob', 5, 5)
ArgumentError: wrong # of arguments(3 for 2)
from [filepath]:50:in `method_missing'
from (irb):23
Replacing the second argument with something other than an Integer appears to work, but of course the argument is supposed to be an Integer… I am now suspecting a problem in either jRuby or the Java classes I integrated into this.
Turns out the problem was actually with the part I omitted from above:
Apparently it had a method “collect” defined which took 2 arguments, which tricked me into thinking it was Enumerable…go figure.