Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/social_engine/core_ext/hash.rb

Instance Method Summary collapse

Instance Method Details

#optional_reverse_merge!(defaults, required = [], symbolize = true) ⇒ Object



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

def optional_reverse_merge!(defaults,required=[],symbolize=true)
  defaults.recursively_symbolize_keys! if symbolize
  return self.reverse_merge!(defaults) if self.blank?
  defaults.each_pair do |k,v|
    if self[k]
      self[k].reverse_merge!(defaults[k])
    else
      self[k] = defaults[k] if required.include? k
    end
  end
  return self
end

#recursively_symbolize_keys!Object



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/social_engine/core_ext/hash.rb', line 2

def recursively_symbolize_keys!
  self.symbolize_keys!
  self.values.each do |v|
    if v.is_a? Hash
      v.recursively_symbolize_keys!
    elsif v.is_a? Array
      v.recursively_symbolize_keys!
    end
  end
  self
end