I have 2 modules,each having 1 class which contains instance variables &
methods.
I want to access instance variables of 1 class from another class of
another module without calling method.
There's a reason you use methods to access a Class' state. If you tamper
directly with the internals then any modification to the internals of
that Class will have an adverse effect on your Module.
Having said that, you should be able to call instance_variable_get on
the class instance, passing the name of the instance variable as an
argument.
There's a reason you use methods to access a Class' state. If you tamper
directly with the internals then any modification to the internals of
that Class will have an adverse effect on your Module.
Even worse: that separation is exactly what OO is all about:
information hiding and separation of concerns.
Having said that, you should be able to call instance_variable_get on
the class instance, passing the name of the instance variable as an
argument.
That's a method call as well. He said
I want to access instance variables of 1 class from another class of
another module without calling method.
Well, the answer to that is: there is no way. (Or do you know one
without a method call?)
Cheers
robert
···
On Mon, Nov 25, 2013 at 10:52 AM, Joel Pearson <lists@ruby-forum.com> wrote: