From: Brian Candler Date: 2010-04-20T05:44:03+09:00 Subject: Re: ya config file parser Roberto Cm wrote: > to load the file on new(), I changed the class like this: > > require 'yaml' > > class ConfigYaml > > def initialize(file) > if file.nil?? then > yaml_conf = YAML.load_file(file) > end > @data = case yaml_conf.nil? > when true then YAML.load_file(file) > else {} > end > update!(data) > end That looks a bit broken - 'data' is a local variable or method, which you don't seem to have, which is different from @data which is an instance variable. You could try this as a starting point: class ConfigYaml def initialize(file) @filename = file load end def load @data = YAML.load_file(@filename) rescue Errno::ENOENT @data = {} end def save File.open(@filename,"w") { |f| f.write YAML.dump(@data) } end ... rest as before end -- Posted via http://www.ruby-forum.com/.