Skip to content

Instantly share code, notes, and snippets.

@jsonperl
Created May 22, 2015 22:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
CheapDB
class CheapDB
def initialize(filename)
@file = "#{filename}.yml"
FileUtils.touch @file
@data = YAML.load_file(@file) || {}
end
def get_or_set(key, &block)
get(key) || set(key, block.call)
end
def get(key)
@data[key]
end
def set(key, value)
@data[key] = value
File.open(@file, 'w') { |f| f.write @data.to_yaml }
value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment