在Ruby中,是否有一种方法可以动态地向类中添加实例变量?例如:
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