Project

General

Profile

Actions

Feature #18742

closed

Introduce a way to tell if a method invokes the `super` keyword

Added by Dan0042 (Daniel DeLorme) about 2 years ago. Updated almost 2 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:108284]

Description

In order to implement a "no clobber" checker as in #18618, I would like to have a way to check if a method calls super or not.

So I'm thinking that something along the line of Method#calls_super? could return true/false if the method simply contains the super keyword. I'm not really interested in handling weird/artificial edge cases with eval and binding and whatnot.

class X
  def a
  end; p instance_method(:a).calls_super? #=> false

  def b
    super
  end; p instance_method(:b).calls_super? #=> true

  def c
    super if false
  end; p instance_method(:c).calls_super? #=> true

  def d
    eval 'super'
  end; p instance_method(:d).calls_super? #=> false (I doubt there's a reasonable way for this to return true)
end

With the above it would be possible to warn against a method that has a super_method but doesn't use the super keyword.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0