Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/itamae-spec/task/base.rb

Instance Method Summary collapse

Instance Method Details

#deep_merge(other_hash, &block) ⇒ Object



10
11
12
# File 'lib/itamae-spec/task/base.rb', line 10

def deep_merge(other_hash, &block)
  dup.deep_merge!(other_hash, &block)
end

#deep_merge!(other_hash, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/itamae-spec/task/base.rb', line 14

def deep_merge!(other_hash, &block)
  merge!(other_hash) do |key, this_val, other_val|
    if this_val.is_a?(Hash) && other_val.is_a?(Hash)
      this_val.deep_merge(other_val, &block)
    elsif block_given?
      yield(key, this_val, other_val)
    else
      other_val
    end
  end
end

#to_pretty_jsonObject



26
27
28
# File 'lib/itamae-spec/task/base.rb', line 26

def to_pretty_json
  MultiJson.dump(self, symbolize_keys: true, pretty: true)
end