From: Ville Mattila Date: 2001-03-20T20:40:02+09:00 Subject: [ruby-talk:12935] How to add accessors dynamically? Hello I危 trying to do simple thing like this class Foo < Module def add_attr(name=nil,value=nil) attr_accessor eval(":" + name) eval("@" + name + "=" + value) end end f = Foo.new f.add_attr("bar", "baz") f.bar #-> "baz" f.bar = "biz" f.bar #-> "biz" Unfortunately I just get faa.rb:5:in `add_attr': (eval):1:in `add_attr': undefined local variable or meth od `baz' for # (NameError) from faa.rb:10:in `eval' from faa.rb:5:in `add_attr' from faa.rb:10 When trying to execute the code above. What have I understood wrong?