I have a class that has N methods.
class MyClass
def self.method_one(params)
#specific code
end
def self.method_two(params)
#specific code
end
end
I need to add the same code for each method created in that class. I need to put the code between "begin and rescue"
I tried the following, but I did not succeed:
class MyClass < BaseClass
add_rescue :method_one, :method_two, Exception do |message|
raise message
end
def self.method_one(params)
#specific code
end
def self.method_two(params)
#specific code
end
end
I created a method to change the methods
class BaseClass
def self.add_rescue(*meths, exception, &handler)
meths.each do |meth|
old = instance_method(meth)
define_method(meth) do |*args|
begin
old.bind(self).call(*args)
rescue exception => e
handler.call(e)
end
end
end
end
end
I always get the error message: undefined method `method_one 'for Myclass: Class