Issue #7274 has been updated by rits (First Last).


matz (Yukihiro Matsumoto) wrote:
> OK, I misunderstood something.
> 
> In case foo is implemented in Base as in the original example, I admit that it will not cause any serious problem.
> 
> But I still have small concern.
> If you are sure foo is implemented in Base, you can retrieve foo from Base (not from Sub),
> so that you don't have to worry about redefinition.
> 
> If you are not, the code will be fragile.  It's a sign of bad code.
> 
> Thus, I'd like to ask you why you want to relax?  Consistency? Any actual use-case?
> If there's actual non trivial use-case, I'd say go.
> 

I discovered the current behavior while playing around, learning about method binding in ruby, not via a bug in my code.  I noticed in irb (to_s) that an unbound method was remembering the class from which it was requested, which struck me as pointless (what difference could it possibly make).  Then I guessed it must be used for something (for no good reason) and sure enough, two unbound method objects referencing the same method on the same class were unequal because they happened to have been requested from different classes.  

This made absolutely no sense, if unbound methods are to have value equality (which they do) it should be based on owner and method name.  This led to the next absurdity of a method being unbindable to an instance of its owner.

I thought such nonsense warranted a fix, so I filed a bug, I suppose you can disagree, but at least now we are on the same page.
 
----------------------------------------
Feature #7274: UnboundMethods should be bindable  to any object that is_a?(owner of the UnboundMethod)
https://bugs.ruby-lang.org/issues/7274#change-43162

Author: rits (First Last)
Status: Rejected
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


=begin
as a corollary, (({UnboundMethod}))s referencing the same method name on the same owner, should be equal

currently (({UnboundMethod}))s 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})).
=end



-- 
http://bugs.ruby-lang.org/