Class: Hash

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

Instance Method Summary collapse

Instance Method Details

#extract(*keys) ⇒ Object



17
18
19
20
21
# File 'lib/left_side/core_ext.rb', line 17

def extract(*keys)
  result = {}
  keys.flatten.each {|key| result[key] = self[key] }
  result
end

#fetch_valuesObject



31
32
33
# File 'lib/left_side/core_ext.rb', line 31

def fetch_values
  self.map{|_, v| v.is_a?(Hash) ? v.fetch_values : v}.join(',').split(',')
end

#fixed_hashObject



23
24
25
26
27
28
29
# File 'lib/left_side/core_ext.rb', line 23

def fixed_hash
  g = {}
  self.each_pair do |k, v|
    g[k.to_s] = v.is_a?(Hash) ? v.fixed_hash : v.to_s
  end
  g
end

#process_each_value(&block) ⇒ Object



35
36
37
# File 'lib/left_side/core_ext.rb', line 35

def process_each_value(&block)
  self.each{|k, v| self[k] = v.is_a?(Hash) ? v.process_each_value(&block) : Array(v).map{|vv| yield vv}}
end