From: ben@... Date: 2006-06-23T13:45:40+09:00 Subject: Quick singleton question Hi, In a structure I'm building, I need to be able to add children (of the same class) to an object, and have the child object know who its parent is. So I can do obj.instance_variable_set(:@parent,parentobj), but that doesn't create the accessor for me, so I still need to do class << child def parent @parent end end That's not really all that onerous, and I can always predefine attr_reader for :parent in the main class to save the second step, but it lead me to wondering if there is a 'nice' way to add an instance variable and its accessor all at once to an object, because that will probably come in handy one day. Initially I wanted to do class << child def parent parentobj end end but obviously that will fail since parentobj is out of scope. Anyway, that's it. :) ben