From: ts Date: 2005-08-29T00:09:32+09:00 Subject: Re: Dynamic methods / accessors >>>>> "F" == Frodo Larik writes: F> # Create first object F> a = MyThing.new F> a.create_method('box','some_value'), so a.box is populated with 'some value' F> # Create second object F> b = MyThing.new F> # I don't want the following to happen F> b.box = 'something other' moulon% cat b.rb #!/usr/bin/ruby class MyThing def create_method(meth, init) class << self; self end.send(:attr_accessor, meth) send("#{meth}=", init) end end a = MyThing.new a.create_method('box','some_value') p a, a.box b = MyThing.new p b b.box = 'something other' moulon% moulon% ./b.rb # "some_value" # ./b.rb:16: undefined method `box=' for # (NoMethodError) moulon% Guy Decoux