I have the following Ruby program:
class Access
def retrieve_public
puts "This is me when public..."
end
private
def retrieve_private
puts "This is me when privtae..."
end
protected
def retrieve_protected
puts "This is me when protected..."
end
end
access = Access.new
access.retrieve_protected
When I run it, I get the following:
accessor.rb:23: protected method `retrieve_protected' called for #<Access:0x3925
758> (NoMethodError)
Why is that?
Thanks.
Because you can call protected methods directly only from within instance method of this object, or or another object of this class (or subclass)