Предполагая следующий неполный код ...
class Foo
@an_array = []
def method_catcher(this_var)
unless self.method_defined? this_var
if an_array.include?[this_var]
p "Doing something with a fake method as if it were real." << this_var
else
p "You attempted to call Foo with " << this_var << " this class will now self destruct, and you will be returned to entry."
end
end
end
end
Как я могу запустить метод method_catcher
для любого метода, который пытался выполнить foo, вместо того, чтобы возвращать NoMethodError
?
Например, если бы я позвонил
Foo.totally_not_a_declared_method_or_class_variable
, чтобы я мог получить любой ответ в зависимости от моего массива вместо того, чтобы выдавать ошибку?