V
Vladimir Agafonkin
Hi!
What is the best way to access class' instance variables from a method
of another instance variable of the same class that is a class itself?
OK, Let's say I have Duck class with an instance variable
@quack_behaviour of QuackBehaviour class inside. Duck#quack method
calls one of the QuackBehaviour methods, and I want to access some of
the intance variables (say, @name) of the caller Duck object from that
method.
One way is to set an attr_accessor :name (or use instance_variable_get)
and pass "self" as a parameter to the @quack_behaviour method. But it
seems for me that it is not the most appropriate way of doing this. Or
is it?
What is the best way to access class' instance variables from a method
of another instance variable of the same class that is a class itself?
OK, Let's say I have Duck class with an instance variable
@quack_behaviour of QuackBehaviour class inside. Duck#quack method
calls one of the QuackBehaviour methods, and I want to access some of
the intance variables (say, @name) of the caller Duck object from that
method.
One way is to set an attr_accessor :name (or use instance_variable_get)
and pass "self" as a parameter to the @quack_behaviour method. But it
seems for me that it is not the most appropriate way of doing this. Or
is it?