Say, I have an object that replies to .hello
method. Now, I want to create another object that will reply to both hello
(and all other methods of the original object) and bye
methods. Something like this:
x = # original object
y = extend(x) do
def bye
# here I can also call methods of the "x" object
puts "Bye"
end
end
This new y
object is essentially a decorator of x
. Is it possible in Ruby?