From: 7stud -- Date: 2011-04-10T06:37:26+09:00 Subject: Re: private vs. protected question 7stud -- wrote in post #991945: > > The protected method rule states that you can use a receiver to call the > method--so long as whatever object is self at that time is also an > object of the same class as the receiver (or a parent or subclass). I think we need to scratch '(or parent...' off the list: class Animal def meth(obj) obj.bark #self=anim whose class is Animal, end #and Animal is a parent class of obj=dog end class Dog < Animal protected def bark puts 'woof' end end dog = Dog.new anim = Animal.new anim.meth(dog) --output:-- prog.rb:3:in `meth': protected method `bark' called for # (NoMethodError) from prog.rb:22:in `
' -- Posted via http://www.ruby-forum.com/.