I have this little code that seems to contradict in some way Ruby's documentation:
The second visibility is
protected
. When calling a protected method the sender must be a subclass of the receiver or the receiver must be a subclass of the sender. Otherwise aNoMethodError
will be raised.
class Test
def publico(otro)
otro.prot
end
end
class Hija < Test
protected def prot; end
end
Test.new.publico(Hija.new)
I get the folowing output:
NoMethodError: protected method `prot' called for # publico
What am I missing? Apparently the option " the receiver must be a subclass of the sender" is not available.
a.n b
case in the example in the doc, which raises an exception, as described. There is conflict within the documentation (In that respect, your question is a bit misleading, but nevertheless raises a good point). – Campobello