No title Revision 653031316238 (Wed Dec 16 2009 at 21:24) - Diff Link to this snippet: https://friendpaste.com/5TdtGPZaEK0DbDBa2DCUyB Embed: manni perldoc borland colorful default murphy trac fruity autumn bw emacs pastie friendly Show line numbers Wrap lines 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152['pp', 'yaml'].each{ |lib| require lib }module YAML def save_file(filename, obj) File.open(filename, "w+"){ |file| file.puts(obj.to_yaml) } obj end module_function :save_fileendclass Hash def rename(old_key, new_key) new_hash = self.dup new_hash[new_key] = new_hash.delete(old_key) new_hash end def rename!(old_key, new_key) self[new_key] = self.delete(old_key) self endendclass YAMLOptions attr_accessor :filename alias set instance_eval # Like Object.tap, but evals the block rather than passing self to it def initialize(filename, &blk) @filename = filename @hash = load set(&blk) if block_given? end def method_missing(method, *args, &block) p method end def save YAML.save_file(@filename, @hash) end def load YAML.load_file(@filename) rescue YAML.save_file(@filename, {}) endendoptions = YAMLOptions.new("./options.yaml")options.set do foo foo = "It aint easy being cheesy!"endputs "#===---"options.foooptions.foo = "It aint easy being cheesy!"