From: Igor Pirnovar Date: 2012-11-04T06:20:59+09:00 Subject: Re: why does UnboundMethod need to remember the class it was retrieved from (not merely owner)? Mean L. wrote in post #1082655: > This does not answer the question. How comes? It is the rule, that you can not bind a method to anything but to the object that is an instance of a subclass of the class of the original object. You are trying to bind it to an instance of its parent or the superclass. See, if you make a subclass 'A' of your 'Sub', all works as spelled out by the Ruby rules, however if you try to bind to the object whose class is the parent of your 'Sub' you get the error, which BTW, spells out precisely what you missed here: class Base; def foo; puts "in Base"; end; end class Sub < Base; end class A < Sub; end base_foo = Base.instance_method :foo sub_foo = Sub.instance_method :foo base_foo.bind(Base.new).call #=> "in Base" sub_foo.bind(A.new).call #=> "in Base" sub_foo.bind(Base.new).call #=> ./b-u_test.rb:24:in `bind': \ bind argument must be an instance \ of Sub (TypeError) \ from ./b-u_test.rb:24:in `
' Regards, igor -- Posted via http://www.ruby-forum.com/.