protected
methods can be called by all inherited classes, private
methods can only be called by the class they're in.
In ruby, self.some_protected_method
works, self.some_private_method
doesn't work.
class Y
def send_private;
self.private_method_x
end
def send_protected;
self.protected_method_x
end
private
def private_method_x; puts "hi I am private"; end
protected
def protected_method_x; puts 'hi i am protected'; end
end
y = Y.new
y.send_private
NoMethodError: private method `private_method_x' called for #<Y:0x007f7febb99b38>
from (irb):3:in `a'
from (irb):11
y.send_protected
hi i am protected
=> nil