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_set
andinstance_variable_get
a.instance_variable_set(:@x, 10) a.instance_variable_get(:@x) # => 10
or just using
instance_eval
a.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?