I\'m thinking in:
class X
def new()
@a = 1
end
def m( other )
@a == other.@a
end
end
x = X.new()
y = X.new()
x.m( y )
There are several methods
Getter:
class X
attr_reader :a
def m( other )
a == other.a
end
end
instance_eval
:
class X
def m( other )
@a == other.instance_eval { @a }
end
end
instance_variable_get
:
class X
def m( other )
@a == other.instance_variable_get :@a
end
end
I don't think ruby has a concept of "friend" or "protected" access, and even "private" is easily hacked around. Using a getter creates a read-only property, and instance_eval means you have to know the name of the instance variable, so the connotation is similar.