it will continue to be my part of the code, which I want to simplify in order to avoid passing an additional argument for each call. Actually, my usecase is what Mis a user library without defining an argument contextfor each method. checkis a method that is not defined by the user.
module M
def do_something(context)
puts "Called from #{context}"
context.check
end
module_function :do_something
end
class Bar
def check
puts "Checking from #{self}..."
end
end
class Foo < Bar
def do_stuff(scope, method)
scope.send method, self
end
end
Foo.new.do_stuff M, :do_something
Is there a way to do the same without passing selfas an input argument to the method do_somethingto retrieve the method check?
module M
def do_something
called_from_object = ???
puts "Called from #{called_from_object}"
called_from_object.check
end
module_function :do_something
end
class Bar
def check
puts "Checking from #{self}..."
end
end
class Foo < Bar
def do_stuff(scope, method)
scope.send methood
end
end
Foo.new.do_stuff M, :do_something
Thanks for your support!
David source
share