privatedoesn't hide method for inherited classes.
See the simple example below:
And we won't get exception at the last line.
class A private def implementation puts 'private A' end end class B < A def api implementation end end B.new.api
So, in fact
privatedo not do what you expect it to do. Use cases that distinguish
protectedare more specific. At first:
implementationmethod can not be called like
self.implementationeven from class A.
Seamless pure gap. You can do such call if the method would be protected. Can't imagine the case when this limitation is useful.
class A def api self.implementation #exception here end private def implementation puts 'private A' end end A.new.api
The second difference is a bit esoteric. Two instances of the same class can access protected methods of each other but not private methods.
class A def api(another) #suppose to receive an instance of a implementation == another.implementation end protected def implementation puts 'private A' end end A.new.api(A.new)
protectedbut fail for
private. Well, this kind of protection do not make a real because of it's rareness.
My conclusion: don't use private at allYou might do any decision on the points above.
My conclusion is to not use
privateat all, because it doesn't give the level of privacy that I expect. Difference form
protectedis so pure that it do not have any real benefits.