Forum: Ruby-core Feature Proposal: Method#super_method

0e610136db92027148906c92d57fdb36?d=identicon&s=25 unknown (Guest)
on 2014-05-02 04:44
(Received via mailing list)
Issue #9781 has been updated by Marc-Andre Lafortune.


Ryan Davis wrote:
> Maybe it is just me misunderstanding something... but this doesn't seem that
complicated. I don't understand why you'd walk through the ancestors when you 
just ask one level up:

For one level, with simple class inheritance, it probably isn't, but
throw in a prepended module or two, and the desire to go up more than
one level (i.e. `obj.method(:foo).super_method.super_method`) and it's
not completely trivial.

If ever we support a module being included more than once in the
ancestry chain, then it's actually impossible (unless Method provides a
more extensive api to tell where it is in the ancestry chain).

I'm +1 for this feature, although I would favor the shorter name
`super`. I don't think it would ever conflict with the keyword, and if
it did there is still the same solution as with `class`, i.e.

Feature #9781: Feature Proposal: Method#super_method

* Author: Richard Schneeman
* Status: Open
* Priority: Normal
* Assignee:
* Category: core
* Target version:

When `super` is called in a method the Ruby VM knows how to find the
next ancestor that has that method and call it. It is difficult to do
this manually, so I propose we expose this information in

Ruby Method class ( is
returned by calling Object.method and passing in a method name
( This
is useful for debugging:

# /tmp/code.rb
class Foo
  def bar

# => ["/tmp/code.rb", 3]

The Object#method allows a ruby developer to easily track the source
location of the method and makes debugging very easy. However if the
code is being invoked by a call to `super` it is difficult to track

# /tmp/code.rb

class BigFoo
  def bar

class Foo < BigFoo
  def bar

In this code sample it is easy to find the method definition inside of
Foo but it is very difficult in large projects to find what code exactly
`super` is calling. This simple example is easy, but it can be hard when
there are many ancestors. Currently if I wanted to find this we can
inspect ancestors

Foo.ancestors[1..-1].map do |ancestor|
  next unless ancestor.method_defined?(:bar)

To make this process simpler I am proposing a method on the Method class
that would return the result of `super`

It could be called like this:


I believe adding Method#super_method, or exposing this same information
somewhere else, could greatly help developers to debug large systems
This topic is locked and can not be replied to.