Class: DeferredHashManipulator
- Inherits:
-
Object
- Object
- DeferredHashManipulator
- Defined in:
- lib/hashlib.rb
Instance Method Summary collapse
- #apply ⇒ Object
-
#initialize(hash) ⇒ DeferredHashManipulator
constructor
A new instance of DeferredHashManipulator.
- #peek ⇒ Object
- #pending_operations ⇒ Object
- #set(path, value) ⇒ Object
- #unset(path) ⇒ Object
Constructor Details
#initialize(hash) ⇒ DeferredHashManipulator
Returns a new instance of DeferredHashManipulator.
2 3 4 5 |
# File 'lib/hashlib.rb', line 2 def initialize(hash) @hash = hash @ops = [] end |
Instance Method Details
#apply ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/hashlib.rb', line 30 def apply() @ops.each do |op| case op[:type] when :set @hash.rset(op[:path], op[:value]) when :unset @hash.unset(op[:path]) end end @ops = [] @hash end |
#peek ⇒ Object
22 23 24 |
# File 'lib/hashlib.rb', line 22 def peek() @hash end |
#pending_operations ⇒ Object
26 27 28 |
# File 'lib/hashlib.rb', line 26 def pending_operations() @ops end |
#set(path, value) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/hashlib.rb', line 7 def set(path, value) @ops << { :type => :set, :path => path, :value => value } end |
#unset(path) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/hashlib.rb', line 15 def unset(path) @ops << { :type => :unset, :path => path } end |