Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/api_mini_tester/test_step.rb
Instance Method Summary collapse
Instance Method Details
#deep_merge(other_hash, &block) ⇒ Object
279 280 281 |
# File 'lib/api_mini_tester/test_step.rb', line 279 def deep_merge(other_hash, &block) dup.deep_merge!(other_hash, &block) end |
#deep_merge!(other_hash, &block) ⇒ Object
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/api_mini_tester/test_step.rb', line 283 def deep_merge!(other_hash, &block) other_hash.each_pair do |current_key, other_value| this_value = self[current_key] self[current_key] = begin if this_value.is_a?(Hash) && other_value.is_a?(Hash) this_value.deep_merge(other_value, &block) elsif block_given? && key?(current_key) block.call(current_key, this_value, other_value) # rubocop:disable Performance/RedundantBlockCall else other_value end end end self end |