Hi, Thanks Drew. I had something like that working too. But the problem is method_missing. What if I want to create a key that happens to have the same name as a method that actually exists? Also, how would you convert that to a hash? Thanks again, Matt On Feb 28, 6:11 pm, Drew Olson <olso... / gmail.com> wrote: > Drew Olson wrote: > > M.W. Mitchell wrote: > >> Hi, > > >> I experimenting with thisconfigclass. 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 :( > > I spoke too soon, it does now :) > > require 'yaml' > > class Configuration > def initialize(filename=nil) > @filename = filename > @hash = {} > end > > def method_missing(name,*args,&block) > if block > config= Configuration.new > config.instance_eval(&block) > @hash[name] =config.hash_value > else > @hash[name] = args.first > end > end > > def store > File.open(@filename,"w") do |out| > out << YAML::dump(@hash) > end > end > > def hash_value > @hash > end > end > > def Configuration filename=nil,&block > config= Configuration.new(filename) > config.instance_eval(&block) > end > > Configuration "my_app.yaml" do > a 10 > b 20 > c 30 > d do > d1 10 > d2 20 > end > > store > end > > -- > Posted viahttp://www.ruby-forum.com/.