I have code as follows:
class A
private
def p_method
puts "I'm a private method from A"
end
end
class B < A
def some_method
p_method
end
end
b = B.new
b.p_method # => Error: Private method can not be called
b.some_method # => I'm a private method from A
b.some_method
calls a private method that is defined in class A
. How can a private method be accessed in the class where it is inherited? Is this behavior the same in all object oriented programming languages? How does Ruby do encapsulation?