I want to store and retrieve some variables from object. For example in a
a = "a"
So far I found two possible ways to do it.
Using
instance_variable_setandinstance_variable_geta.instance_variable_set(:@x, 10) a.instance_variable_get(:@x) # => 10or just using
instance_evala.instance_eval { @y = 5 } a.instance_eval { @y } # => 5
The second approach looks shorter and simpler for me, is there anything wrong with my code if I prefer this one?