From: Fasun Lau Date: 2009-05-01T19:38:52+09:00 Subject: Re: Question about "protected" and "private" --0016363ba86810d2e60468d76b39 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Got it! Thanks very much! 2009/5/1 Shaun Keller > > In most OO languages, private methods can only be called from within the > defining class. > > ie > > class MyClass > > def method1 > method2 > end > > private > > def method2 > end > end > > A protected method can also be called from subclasses. So if method2 was > protected, and MySubClass < Class, then method2 could be called from > within MySubClass. > > > In ruby, private and protected methods can be called by any instance of > the defining class or its subclasses, but private methods cannot have an > explicit receiver. > > In short, the difference is that protected methods can be called from > within a class on ANY OBJECT of that class or its subclasses. > > See http://blog.zerosum.org/2007/11/22/ruby-method-visibility for more > details > -- > Posted via http://www.ruby-forum.com/. > > -- Fasun Lau --0016363ba86810d2e60468d76b39--