Class: Observed::Hash::Builder

Inherits:
Object
  • Object
show all
Includes:
KeyPathEncoding
Defined in:
lib/observed/hash/builder.rb

Instance Method Summary collapse

Methods included from KeyPathEncoding

#at_key_path_on_hash

Constructor Details

#initialize(defaults = {}) ⇒ Builder

Returns a new instance of Builder.



8
9
10
# File 'lib/observed/hash/builder.rb', line 8

def initialize(defaults={})
  @hash = defaults.dup
end

Instance Method Details

#[]=(key_path, value) ⇒ Object



12
13
14
15
16
# File 'lib/observed/hash/builder.rb', line 12

def []=(key_path, value)
  at_key_path_on_hash @hash, key_path, create_if_missing: true do |h, k|
    h[k] = value
  end
end

#buildObject



18
19
20
# File 'lib/observed/hash/builder.rb', line 18

def build
  @hash
end