From: Rob Rypka Date: 2005-10-07T12:18:10+09:00 Subject: Re: is there a way to add attributes to instances? On 10/6/05, James Edward Gray II wrote: > On Oct 6, 2005, at 9:36 PM, ako... wrote: > > is there a way to add properties to instances and access them later > > just like if they were defined in the object's class? > > Here's two different ideas to get you going: > > irb(main):001:0> require "ostruct" > => true > irb(main):002:0> a = OpenStruct.new > => > irb(main):003:0> a.new_property = 123 > => 123 > irb(main):004:0> a.property > => nil I think OpenStruct is what you want to use. If you feel you have to implement it yourself, or it's not quite right, think about using method_missing. It is perhaps the most awsomely useful concepts in Ruby. -- Rob