我的班级是:
class Mycfg @@options = {} def init @@options = YAML.load_file(Dir.pwd + PATH) end def set(key,val) @@options[key] = val end def get(key) @@options[key] end def save end end
使用这个类:
oj = Mycfg.new oj.init if oj.get 'name' == 'tom' oj.set 'changed',Data.now end oj.save
YAML文件:
name : tom pawd : 123456 version : 0.0.1 created : 2011-10-24 changed : 2011-10-24