Reputation: 1849
So my research on this seems to indicate that the there is something in here that is causing infinite recursion, but I'm not sure waht it is. Can anyone point out what I'm doing wrong?
def initialize(_val)
@start_value = _val
end
def method_missing(method, *args)
if method.starts_with?("plus") then
num = method[4 .. method.length]
if (/^[\d]+(\.[\d]+){0,1}$/ === num) then
number = Integer(num)
self.class_eval("def #{method}; return @start_value + x; end")
self.plus(number)
else
super.method_missing
end
else
super.method_missing
end
end
end
Upvotes: 0
Views: 218
Reputation: 15772
You shouldn't do this:
super.method_missing
You want this:
super
In both cases you'd be using super
with no args, which is the proper way to call an ancestor's version of a method, in this case method_missing
. But in your version you're then calling method_missing
redundantly on the result, which is where it gets all infinitey.
Upvotes: 1
Reputation: 7403
The most obvious explanation would be if you don't have plus
defined as an instance method. But why not add a puts method
to the top of your method_missing
method so you can see what's going on?
Upvotes: 1