From: Paul Brannan Date: 2003-12-17T00:10:13+09:00 Subject: Re: UnboundMethods Useless? On Tue, Dec 16, 2003 at 05:09:00AM +0900, T. Onoma wrote: > If I can only bind the method to an object of the same class from > which I took it, then what's the point!? What am I missing? It's not useless; I found at least one use for it in [ruby-talk:29122]. In trying to demonstrate an additional use, I came across this peculiarity: class Base def foo puts "Base#foo" end end class Derived < Base def foo puts "Derived#foo" super end end base_foo = Base.instance_method(:foo) Derived.__send__(:define_method, :foo, base_foo) # If I leave the following line out, then Derived.new.foo() results in: # test.rb:32: private method `foo' called for # (NameError) Derived.__send__(:public, :foo) # The following code produces (on Ruby 1.6): # test.rb:18:in `foo': bind argument must be an instance of Base (TypeError) # from test.rb:18 # But on Ruby 1.8 it prints Base#foo as expected. Derived.new.foo() Can someone explain to me what's happening here? Paul