In Ruby, is there a way to dynamically add a instance variable to a class? For Example:
class MyClass
def initialize
create_attribute("name")
end
def create_attribute(name)
attr_accessor name.to_sym
end
end
o = MyClass.new
o.name = "Bob"
o.name
One way (there are others) is to use
instance_variable_setandinstance_variable_getas so: