How can I add an instance variable to a defined class at runtime, and later get and set its value from outside of the class?
I\'m looking for a metaprogramming so
Ruby provides methods for this, instance_variable_get and instance_variable_set. (docs)
instance_variable_get
instance_variable_set
You can create and assign a new instance variables like this:
>> foo = Object.new => # >> foo.instance_variable_set(:@bar, "baz") => "baz" >> foo.inspect => #