The closest I can find is In Ruby, how do I check if method "foo=()" is defined?, but it only works if the method is public, even when inside the class block.
What I want:
class Foo
private
def bar
"bar"
end
magic_private_method_defined_test_method :bar #=> true
end
What I've tried:
class Foo
private
def bar
"bar"
end
respond_to? :bar #=> false
#this actually calls respond_to on the class, and so respond_to :superclass gives true
defined? :bar #=> nil
instance_methods.include?(:bar) #=> false
methods.include?(:bar) #=> false
method_defined?(:bar) #=> false
def bar
"redefined!"
end # redefining doesn't cause an error or anything
public
def bar
"redefined publicly!"
end #causes no error, behaves no differently whether or not #bar had been defined previously
end