Class: Layer::Patch::Hash

Inherits:
Base
  • Object
show all
Defined in:
lib/layer/patch/hash.rb

Instance Attribute Summary

Attributes inherited from Base

#patch

Instance Method Summary collapse

Methods inherited from Base

#initialize, #wrap

Constructor Details

This class inherits a constructor from Layer::Patch::Base

Instance Method Details

#[]=(key, value) ⇒ Object Also known as: store



11
12
13
14
# File 'lib/layer/patch/hash.rb', line 11

def []=(key, value)
  patch.set(key, value.dup)
  super(key, wrap(key, value))
end

#clearObject



17
18
19
20
# File 'lib/layer/patch/hash.rb', line 17

def clear
  patch.replace({})
  super
end

#delete(key) ⇒ Object



22
23
24
25
# File 'lib/layer/patch/hash.rb', line 22

def delete(key)
  patch.delete(key)
  super
end

#delete_if(&block) ⇒ Object Also known as: reject!



27
28
29
30
31
32
33
# File 'lib/layer/patch/hash.rb', line 27

def delete_if(&block)
  super do |key, value|
    result = yield(key, value)
    delete(key) if result
    result
  end
end

#merge!(other_hash) ⇒ Object



46
47
48
49
50
51
# File 'lib/layer/patch/hash.rb', line 46

def merge!(other_hash)
  other_hash.each_pair do |key, value|
    patch.set(key, value)
  end
  super
end

#prepare_base(base) ⇒ Object



5
6
7
8
9
# File 'lib/layer/patch/hash.rb', line 5

def prepare_base(base)
  base.each_pair do |key, value|
    base[key] = wrap(key, value)
  end
end

#replace(other_hash) ⇒ Object



41
42
43
44
# File 'lib/layer/patch/hash.rb', line 41

def replace(other_hash)
  patch.replace(other_hash)
  super
end

#shiftObject



36
37
38
39
# File 'lib/layer/patch/hash.rb', line 36

def shift
  patch.delete(keys.first)
  super
end