Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/app_yml/core_ext.rb,
lib/generators/app_yml/install/templates/app.rb

Overview

Public: Extends Ruby’s Hash class to provide a method for performing a deep update on a hash.

Instance Method Summary collapse

Instance Method Details

#deep_update!(new_hash = {}) ⇒ Object

Public: Performs an in-place deep update on the calling hash with the provided ‘new_hash’. Allows us to override ‘app.yml’ settings from the ‘all’ environment with the current environment (test/development/staging/production) with unlimited nesting.

new_hash - The hash to copy over the calling hash.

Examples

{ :email => '[email protected]', :name => 'Graham Swan' }.deep_update!({ :email => '[email protected]' })
=> { :email => '[email protected]', :name => 'Graham Swan' }

Returns the calling hash with the updated values.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/app_yml/core_ext.rb', line 14

def deep_update! new_hash={}
  new_hash.each_pair do |key, val|
    if val.class.eql? Hash
      self[key].deep_update! val
    else
      self[key] = val
    end
  end
  
  self
end