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
You shouldn’t do this:
You want this:
In both cases you’d be using
superwith no args, which is the proper way to call an ancestor’s version of a method, in this casemethod_missing. But in your version you’re then callingmethod_missingredundantly on the result, which is where it gets all infinitey.