class Wardrobe::Store

Attributes

parent[R]
store[R]

Public Class Methods

new() click to toggle source
# File lib/wardrobe/store.rb, line 8
def initialize
  @store = {}
  freeze
end

Public Instance Methods

[](name) click to toggle source
# File lib/wardrobe/store.rb, line 17
def [](name)
  store[name]
end
del(name) click to toggle source
# File lib/wardrobe/store.rb, line 46
def del(name)
  mutate do
    store.delete(name) { |key| raise "#{key} not found" }
  end
end
each(&blk) click to toggle source
# File lib/wardrobe/store.rb, line 21
def each(&blk)
  store.each(&blk)
end
freeze() click to toggle source
Calls superclass method
# File lib/wardrobe/store.rb, line 25
def freeze
  store.freeze
  super
end
merge(other, _calling_object, _config) click to toggle source
# File lib/wardrobe/store.rb, line 38
def merge(other, _calling_object, _config)
  mutate do
    @store = store.merge(other.store)
    # I guess we have to loop through each item and do a custom merge...
    # maybe not use Hash#merge?
  end
end
method_missing(name, *args, **key_args, &block) click to toggle source
Calls superclass method
# File lib/wardrobe/store.rb, line 30
def method_missing(name, *args, **key_args, &block)
  if (atr = store[name])
    atr
  else
    super
  end
end
values() click to toggle source
# File lib/wardrobe/store.rb, line 13
def values
  store.values
end

Private Instance Methods

mutate(&blk) click to toggle source
# File lib/wardrobe/store.rb, line 54
def mutate(&blk)
  dup.instance_exec do
    @store = store.dup
    instance_exec(&blk)
    freeze
  end
end