From: goodieboy Date: 2008-03-15T02:22:19+09:00 Subject: Re: Help with the DSL (ish) config class Thought I'd just update this as it's exactly what I was trying to do - have the config settings in a file, but only the block contents. Now in your config file, you can do: # my_config.rb rows 10 query_fields [:name,:address] facets { fields [:business,:product_category] offset 0 } And to turn that into a Hash: Config.load_from_file('my_config.rb').to_hash Neat! -matt ============ class Config instance_methods.each { |m| undef_method m unless (m =~ /^__/) or ['class', 'instance_eval'].include?(m) } def initialize(init_data=nil, &block) @d = init_data || {} instance_eval(&block) if block_given? end def to_hash; @d; end def self.load_from_file(file) self.new.instance_eval File.read(file) end protected def method_missing(method, data=nil, &block) @d[method] = data return @d[method] = self.class.new(data, &block).to_hash if data.nil? @d end end