On Tue, May 3, 2011 at 3:50 AM, Clifford Heath <no / spam.please.net> wrote:
> On 05/03/11 13:35, Christopher Dicely wrote:
>>
>> On Mon, May 2, 2011 at 8:15 PM, Clifford Heath<no / spam.please.net> wrote:
>>>
>>> On 05/03/11 11:13, Adam Prescott wrote:
>>>>
>>>> On Tue, May 3, 2011 at 1:45 AM, 7stud --<bbxx789_05ss / yahoo.com>
>>>> wrote:
>>>>>
>>>>> Instance methods are private by default. If you define an accessor
>>>>> method, then they become public-like:
>>>>
>>>> I think you meant to say "instance variables", not "methods".
>>>
>>> and instance variables are available to all subclasses, also
>>> when the class is re-opened... so "protected", not private.
>>
>> The instance variables of an object are not available outside of the
>> instance (well, except via intrusive methods like
>> #instance_variable_set),
>
> Correct.
>
>> so Ruby instance variables are more like
>> private data variables than protected ones.
>
> Incorrect. Protected means unavailable outside this class, except to
> subclasses. What definition of "protected" are you using?

In Java, protected means available to:
1.  methods (class [static] or instance) of this class and objects of this class
2. methods (class [static] or instance) of subclasses of this class
and objects of those subclasses
3. methods (class [static] or instance) of classes defined in the same
package as this class, and objects of those classes

In Java private means available to:
methods (class [static] or instance) of this class and objects of this class

In C++, protected means available to:
members and friends of the base class in which the protected member is
defined, and members and friends of any classes derived from that base
class.

In C++, private means availabe to:
members and friends of the base class in which the protected member is defined.

In Ruby, an instance variable can be directly accessed from:
methods of the object in which it exists, regardless of on which class
or module those methods are defined.

This is far more restrictive than protected access in Java and C++,
and simultaneous more restrictive (does not allow methods on other
objects -- including objects of the same class and the object which is
the class -- to access instance variables of an object) and less
restrictive (allows instance methods on the same object to access
instance variables of the object even when those methods were not
defined in the same class/module.)

I stand by the characterization that access to Ruby instance variables
 is more like private access than protected access; in fact, its
pretty much identical to private access for methods in Ruby, which
differs from languages like Java and C++ in that private access
restricts based on the specific object, not the class. Its certainly
unlike Ruby protected access, which allows access to members from
members of other instances of subclasses of the class of which the
object is a class.