Skip to content

Instantly share code, notes, and snippets.

@clicube
Last active December 10, 2015 19:39
Show Gist options
  • Save clicube/4482749 to your computer and use it in GitHub Desktop.
Save clicube/4482749 to your computer and use it in GitHub Desktop.
SimpleStore is initialized with file path of YAML file, can be used like Hash, and can be saved to the file.
# coding: utf-8
require 'yaml'
class SimpleStore < BasicObject
attr_reader :file
def initialize(file)
@file = file
if(::File::exist?(file))
@data ||= ::YAML::load(open(file))
else
@data = {}
end
end
def save
::File.open(file, 'w') { |f| f.write(::YAML.dump(@data)) }
self
end
def method_missing(*args, &block)
@data.__send__(*args,&block)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment