My question is based on an answer to the topic “redefining a single ruby method on a single instance with a lambda”.
How can I redefine a method and from within the new method call the original definition? Other instances of
# call original `some_object.some_method` here
some_object.some_method is not a singleton method, then you can just call
super in your redefined method.
def some_object.some_method super do_something_else end
some_object.some_method is a singleton method, then
You can define that method in a module
module SomeModule def some_method super do_something_else end end
And then prepend it to the singleton class of the object
You have to make an alias then redefine, since there is no
class << some_object # open the singleton class of some_object alias some_method_original some_method def some_method some_method_original do_something_else end end