From: Drew Olson Date: 2008-02-29T08:05:47+09:00 Subject: Re: Help with the DSL (ish) config class M.W. Mitchell wrote: > Hi, > > I experimenting with this config class. I'm hoping to get something > really easy to write and I'm on to something here, well at least I > thought I was. This class allows me to build a nested Has like: I threw this together in a few minutes, doesn't support nested hashes though :( It writes out your hash to a .yaml file that you can read in later. - Drew require 'yaml' class Configuration def initialize(filename) @filename = filename @hash = {} end def method_missing(name,*args) @hash[name] = args.first end def store File.open(@filename,"w") do |out| out << YAML::dump(@hash) end end end def Configuration filename,&block config = Configuration.new(filename) config.instance_eval(&block) end Configuration "my_app.yaml" do a 10 b 20 c 30 store end -- Posted via http://www.ruby-forum.com/.