From: "rits (First Last)" Date: 2013-09-16T08:24:32+09:00 Subject: [ruby-core:57228] [ruby-trunk - Feature #7274] UnboundMethods should be bindable to any object that is_a?(owner of the UnboundMethod) Issue #7274 has been updated by rits (First Last). marcandre (Marc-Andre Lafortune) wrote: > matz (Yukihiro Matsumoto) wrote: > > The structure of instances of subclass (TT_XXX) may be different from superclasses. > > In that case, the C implemented methods would crash. > > I'm not sure I understand exactly what you are saying, but I am sure that the proposed patch would not cause crashes. Do you had a concrete example in mind? > > Note that the request is not about binding methods across unrelated classes or going from a subclass up to a superclass (both of which could create crashes). It is only about using the actual owner instead of the class used to access it. > > Can you explain why, for example, Kernel#dup can be bound to a String, but not if it was accessed using Array, even though the exact same code would be executed? > > Kernel.instance_method(:dup).bind("hello") # => accepted > Array.instance_method(:dup).bind("hello") # => raises error, but really this is the same method. It's also not clear to me what the concern is, please explain. ---------------------------------------- Feature #7274: UnboundMethods should be bindable to any object that is_a?(owner of the UnboundMethod) https://bugs.ruby-lang.org/issues/7274#change-41843 Author: rits (First Last) Status: Rejected Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: core Target version: next minor as a corollary, UnboundMethods referencing the same method name on the same owner, should be equal currently UnboundMethods binding is determined by the class via which they were retrieved, not the owner ____________________________________ class Base; def foo; end end class Sub < Base; end base_foo = Base.instance_method :foo sub_foo = Sub.instance_method :foo sub_foo.bind(Base.new).call __________________________________ sub_foo.owner is Base so there does not seem to be any reason why it's not safe for it to bind to an instance of Base. and there does not seem to be any reason for sub_foo and base_foo to be unequal, they both refer to the same method, foo on Base. -- http://bugs.ruby-lang.org/