Patch to delegate.rb

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
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Patch to delegate.rb"
on Wed, 29 Jun 2005 23:55:41 +0900, (e-mail address removed) writes:

|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.

Nice idea. It will be merged. Thank you.

matz.
 
A

Austin Ziegler

In message "Re: Patch to delegate.rb"
=20
|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.
=20
Nice idea. It will be merged. Thank you.

Should not the same be done to #respond_to? on the delegator, or is
that not done normally?

-austin
--=20
Austin Ziegler * (e-mail address removed)
* Alternate: (e-mail address removed)
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: Patch to delegate.rb"

|Should not the same be done to #respond_to? on the delegator, or is
|that not done normally?

You're right. Thank you.

matz.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,489
Latest member
BrigidaD91

Latest Threads

Top