From: "David A. Black" Date: 2003-12-10T20:33:44+09:00 Subject: Re: Request for comments (longish) Hi -- On Wed, 10 Dec 2003, Luke A. Kanies wrote: > class Operation > @derivatives = {} > attr_reader :retrieve, :object > attr_writer :retrieve, :fix, :object > > # operations will be retrieved from the base class by name > # should i be using symbols here instead of strings? I don't think it matters, except that it might be a little faster with symbols if you're doing lots of hash access. If you just want to give people the choice, you can canonicalize the object with #to_s or #intern. > def Operation.[](name) > unless @derivatives.include?(name) > raise "No class Operation::#{name}" > end > > return @derivatives[name] > end This is a place where you could, conceivably, use my favorite 1.8.0-and-greater "trick": class Operation @derivatives = Hash.new {|k,v| raise "No class Operation::#{v}" } # ... def Operation.[](name) @derivatives[name] end :-) David -- David A. Black dblack@wobblini.net