From: Dave Burt Date: 2005-09-29T21:36:44+09:00 Subject: Re: Concerning persistency techniques Christophe Poucet: > The other remark I had was more of a question. I have an object > manager that tracks a whole set of objects (each with their own unique > id). This object manager is able to save and load (currently to YAML, > but that is to be changed soon). However one problem is that that all > the class-types that could be saved have to be known by this object > manager. This results into the following code: > > > > Does anyone have any suggestions on how to tackle this problem > differently? The following, taken from Ruby's docs, "implements a perverse kind of autoload facility" which may nevertheless solve a large part of your problem. The part that it won't solve may be solved by the addition of a lookup table mapping class names to their respective require paths. def Object.const_missing(name) @looked_for ||= {} str_name = name.to_s raise "Class not found: #{name}" if @looked_for[str_name] @looked_for[str_name] = 1 file = str_name.downcase require file klass = const_get(name) return klass if klass raise "Class not found: #{name}" end Cheers, Dave