Actions
Feature #18742
closedIntroduce a way to tell if a method invokes the `super` keyword
Feature #18742:
Introduce a way to tell if a method invokes the `super` keyword
Status:
Rejected
Assignee:
-
Target version:
-
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