From: Frederick Cheung Date: 2011-12-05T23:20:54+09:00 Subject: Re: Dynamic instances of a class. On Dec 4, 3:05 am, "Andres M." wrote: > OK, hate to multi-post, but wanted to let you know that i made it, is > not really elegant, i wish there was a better way to do it, but at least > i (kind of) get a solution for the main problem on this post. > > Here is the code. > > require 'csv' > > class Motorcycle >   attr_reader :name, :weight >   @@count = 0 > >   def self.find (name) >     found = nil >     ObjectSpace.each_object(Motorcycle) { |o| >       found = o if o.name == name >     } >     return found >   end Be careful here, because you are only referring to your Motorcycle instances via ObjectSpace if ruby's garbage collection runs it will think that none of those objects are used anymore and would destroy them. ObjectSpace isn't something you want to be using as your 'storage' system (think of it more as a debugging tool). Fred