Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/left_side/core_ext.rb
Instance Method Summary collapse
- #extract(*keys) ⇒ Object
- #fetch_values ⇒ Object
- #fixed_hash ⇒ Object
- #process_each_value(&block) ⇒ Object
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_values ⇒ Object
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_hash ⇒ Object
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 |