>>>>> "F" == Frodo Larik <lists / elasto.nl> 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
#<MyThing:0xb7d70958 @box="some_value">
"some_value"
#<MyThing:0xb7d70804>
./b.rb:16: undefined method `box=' for #<MyThing:0xb7d70804> (NoMethodError)
moulon% 


Guy Decoux