From: "byroot (Jean Boussier)" Date: 2022-04-19T23:18:30+00:00 Subject: [ruby-core:108300] [Ruby master Feature#18742] Introduce a way to tell if a method invokes the `super` keyword Issue #18742 has been updated by byroot (Jean Boussier). You could walk the method Iseq like in this example script: https://github.com/ruby/ruby/pull/5809, and look for the `invokesuper` instruction. That would be MRI specific, but would work today without any change. ---------------------------------------- Feature #18742: Introduce a way to tell if a method invokes the `super` keyword https://bugs.ruby-lang.org/issues/18742#change-97320 * Author: Dan0042 (Daniel DeLorme) * Status: Open * Priority: Normal ---------------------------------------- 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. ```ruby 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. -- https://bugs.ruby-lang.org/ Unsubscribe: