Bug #7987

Method#parameters should consider a prepended or refined methd

Added by Nobuhiro IMAI about 1 year ago. Updated 1 day ago.

[ruby-core:53037]
Status:Closed
Priority:Normal
Assignee:-
Category:core
Target version:-
ruby -v:ruby 2.1.0dev (2013-02-28 trunk 39535) [x86_64-linux] Backport:

Description

In the following example, Method#parameters tell the number of argument is one,
but actual methods take two arguments. I got confused..

 RUBY_DESCRIPTION # => "ruby 2.1.0dev (2013-02-28 trunk 39535) [x86_64-linux]"

 module PM
   def m(a, b)
     :pm
   end
 end

 class PC
   prepend PM

   def m(a)
     :pc
   end
 end

 pm = PC.instance_method(:m)
 pm.owner # => #<PC:0x00000001285888>
 pm.parameters # => [[:req, :a]]
 pc = PC.new
 pc.method(:m).owner # => #<PC:0x00000001285888>
 pc.method(:m).parameters # => [[:req, :a]]
 pc.m(:a) # => ArgumentError
 pc.m(:a, :b) # => :pm

 class RC
   def m(a)
     :rc
   end
 end

 module RM
   refine RC do # !> Refinements are experimental, and the behavior may change in future versions of Ruby!
     def m(a, b)
       :rm
     end
   end
 end

 using RM

 rm = RC.instance_method(:m)
 rm.owner # => RC
 rm.parameters # => [[:req, :a]]
 rc = RC.new
 rc.method(:m).owner # => RC
 rc.method(:m).parameters # => [[:req, :a]]
 rc.m(:a) # => ArgumentError
 rc.m(:a, :b) # => :rm

Related issues

Related to ruby-trunk - Bug #7993: owner of methods defined after using Module#prepend Closed 03/01/2013

History

#1 Updated by Nobuyoshi Nakada 1 day ago

  • Status changed from Open to Closed
  • Description updated (diff)

Seems fixed already.

#2 Updated by Nobuyoshi Nakada 1 day ago

  • Related to Bug #7993: owner of methods defined after using Module#prepend added

Also available in: Atom PDF