In Java I can do:
public boolean equals(Object other) {
return this.aPrivateVariable == ((MyClass)other).aPrivateVariable;
}
This allows me to define equality without breaking the encapsulation of my class.
How can I do the same in Ruby?
Thanks.
In ruby instance variables as well as private methods are accessible only to the object itself, not to any other object no matter their class. Protected methods are available to the object itself and other objects of the same class.
So to do what you want you can define a protected getter-method for your variable.
Edit: An example: