From: James Edward Gray II Date: 2006-06-01T03:51:00+09:00 Subject: Re: OO / Private verse Protected On May 31, 2006, at 1:35 PM, Paul D. Kraus wrote: > Can someone give me an example of when a private method would be more > appropaiate then a protected one? > > I understand the definition of the two but I don't quit understand > the uses. > > A protected method is only accessible from other objects derived > from the > same class. > A private method is basically the same thing but can only be called > by the > current object. > > *shrug* how are those two things different. > When would you ever have an instance that is going to call a method > from > another instance? Maybe in a situation like: >> class MyClass >> def initialize >> @secret_data = 5 >> end >> def ==( other ) >> secret_data == other.secret_data >> end >> protected >> attr_reader :secret_data >> end => nil James Edward Gray II