From: James Edward Gray II Date: 2006-12-13T23:45:15+09:00 Subject: Re: Is there a class that is equivalent to Properties in Java On Dec 13, 2006, at 6:59 AM, Olivia Dou wrote: > Is there a class in the ruby lib that is equivalent to Properties > class > in Java? I think the following code should cover most of the Properties class features: #!/usr/bin/env ruby -w require "forwardable" require "yaml" class Properties def self.load(file_path) File.open(file_path) { |file| YAML.load(file) } end def initialize @properties = Hash.new @defaults = nil end attr_accessor :defaults extend Forwardable def_delegator :@properties, :[]= def [](property) if @defaults and not @properties.include? property @defaults[property] else @properties[property] end end def save(file_path) File.open(file_path, "w") { |file| YAML.dump(self, file) } end end __END__ Hope that helps. James Edward Gray II