Project

General

Profile

Actions

Feature #10216

closed

Add methods to Method and UnboundMethod classess to retrieve method instance for super

Added by radarek (Radosław Bułat) about 8 years ago. Updated 9 months ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:64862]

Description

Because of ruby dynamism nature it is very usefull to check method source location directly in irb/pry by SomeClass.instance_method(:foo).source_location. Very often checked method will call super method and we also want to check this method. And this quite hard to find because super method can be defined in any included class or in parent class. Here is my proposal: add super_method to Method and UnboundMethod classes. This method should return corresponding Method or UnboundMethod instance representing next method in super chain list (or nil if there is no one).

For example:

module A
  def foo
    puts "from A"
  end
end

class X
  include A

  def foo
    puts "from X"
    super
  end
end
> foo_method = X.instance_method(:foo)
#<UnboundMethod: X#foo>
> foo_method.source_location
["/private/tmp/t/feature.rb", 10]
> foo_method.bind(X.new).call
from X
from A
nil

> # this is feature proposal
> super_foo_method = foo_method.super_method
> #<UnboundMethod: X(A)#foo>
> super_foo_method.source_location
["/private/tmp/t/feature.rb", 2]
> super_foo_method.bind(X.new).call
from A
nil

> super_method_foo.super_method
nil

Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Feature #9781: Feature Proposal: Method#super_methodClosedokkez (okkez _)04/28/2014Actions

Updated by nobu (Nobuyoshi Nakada) about 8 years ago

  • Is duplicate of Feature #9781: Feature Proposal: Method#super_method added

Updated by nobu (Nobuyoshi Nakada) about 8 years ago

  • Status changed from Open to Closed
Actions #3

Updated by hsbt (Hiroshi SHIBATA) 9 months ago

  • Project changed from 14 to Ruby master
Actions

Also available in: Atom PDF