The following code works:
class MyClass
def method_a
method_b
end
private
def method_b
puts "Hello!"
end
end
m = MyClass.new
m.method_a
Changing the call to method_b to self.method_b
however does not work:
def method_a
self.method_b
end
I get a NoMethodError
. I'm under the impression that self
just resolves to the instance of the class when inside an instance method. Why does self.method_b
cause problems?
Note: self.method_b
works when private
is changed to protected
.
Note: if the above methods are changed to class methods then calling self.method_b
from method_a doesn't throw the NoMethodError
.