How to retrieve caller context object in Ruby ?
- by David
Hi, hereafter is my piece of code that I want to simplify in order to avoid passing an extra argument on each call :
module M
def do_something(context)
puts "Called from #{context}"
end
module_function :do_something
end
class Foo
def do_stuff
M.do_something(self)
end
end
Foo.new.do_stuff
Is there a way to do the same think without passing 'self' as an input argument to 'do_something' method like this ?
module M
def do_something
puts "Called from #{method that returns caller object}"
end
module_function :do_something
end
class Foo
def do_stuff
M.do_something
end
end
Foo.new.do_stuff
Thanks for your support!