C
christophe.poucet
Hello,
I propose the following patch to delegate.rb. In fact it could be used
to replace the entire eval loop that adds methods to Delegator. It is
necessary because the delegator that is existent now will not find
methods that have been added after a delegator has been created.
foo = Object.new
def foo.foo
puts "foo"
end
foo.plop # => foo
foo2 = SimpleDelegator.new(foo)
foo2.plop # => foo
def foo.bar
puts "bar"
end
foo.bar # => bar
foo2.bar # => NoMethodError
The proposed patch will make the last line, "foo2.bar" react as
expected, namely... print "bar". The patch is:
-------------------------------------------------------------------------------
class SimpleDelegator
def method_missing(m, *args)
unless @_sd_obj.respond_to?(m)
super(m, *args)
end
@_sd_obj.__send__(m, *args)
end
end
I propose the following patch to delegate.rb. In fact it could be used
to replace the entire eval loop that adds methods to Delegator. It is
necessary because the delegator that is existent now will not find
methods that have been added after a delegator has been created.
foo = Object.new
def foo.foo
puts "foo"
end
foo.plop # => foo
foo2 = SimpleDelegator.new(foo)
foo2.plop # => foo
def foo.bar
puts "bar"
end
foo.bar # => bar
foo2.bar # => NoMethodError
The proposed patch will make the last line, "foo2.bar" react as
expected, namely... print "bar". The patch is:
-------------------------------------------------------------------------------
class SimpleDelegator
def method_missing(m, *args)
unless @_sd_obj.respond_to?(m)
super(m, *args)
end
@_sd_obj.__send__(m, *args)
end
end