The two invocations of an instance method carry different semantics. The first call to bar
works as expected.
class T
def foo
bar # <= This works. "bar" is printed.
self.bar # <= EXCEPTION: `foo': private method `bar' called for ...
end
private
def bar
puts 'bar'
end
end
t = T.new
t.foo
I'd like to understand why. What causes self.bar
to have a different semantics, throwing an exception? I'm not interested in the exception per se since I can work around with the dubious removal of the private
label, but primarily interested in the semantic discussion.