class Cistern::Data::Hash
Attributes
default[R]
hash[R]
Public Class Methods
new(_options = {}, &default)
click to toggle source
# File lib/cistern/data/hash.rb, line 6 def initialize(_options = {}, &default) @hash = {} @default = default end
Public Instance Methods
clear()
click to toggle source
# File lib/cistern/data/hash.rb, line 11 def clear hash.clear end
fetch(key, *args)
click to toggle source
# File lib/cistern/data/hash.rb, line 23 def fetch(key, *args) assign_default(key) hash.fetch(key, *args) end
Also aliased as: []
store(key, *args)
click to toggle source
# File lib/cistern/data/hash.rb, line 15 def store(key, *args) assign_default(key) hash.store(key, *args) end
Also aliased as: []=
Protected Instance Methods
assign_default(key)
click to toggle source
# File lib/cistern/data/hash.rb, line 35 def assign_default(key) default.call(hash, key) if !hash.key?(key) && default end