Let's say I have the following 2 classes:
class A def a_method end end class B < A end
Is it possible to discover from inside (an instance) of class B that the a_method method a_method defined only in the superclass, so it is not overridden in B?
Update: Solution
While I marked Chuck’s answer as “accepted,” Paolo Perrota later made me realize that the solution seems to be simpler, and it will probably work with earlier versions of Ruby.
Detection if "a_method" is overridden in B:
B.instance_methods(false).include?("a_method")
And for class methods, we use singleton_methods as follows:
B.singleton_methods(false).include?("a_class_method")
ruby metaprogramming
mxgrn
source share