Class: Hash
- Inherits:
- 
      Object
      
        - Object
- Hash
 
- Defined in:
- lib/ky/hash.rb
Overview
specifically for HashWithIndifferentAccess < Hash, instead of plain to_yaml
Instance Method Summary collapse
- #compact_blank(opts = {}) ⇒ Object
- #to_hash_recursive ⇒ Object
- 
  
    
      #to_plain_yaml(opts = {})  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    which yields ugly !map:ActiveSupport::HashWithIndifferentAccess. 
Instance Method Details
#compact_blank(opts = {}) ⇒ Object
| 18 19 20 21 22 23 24 25 | # File 'lib/ky/hash.rb', line 18 def compact_blank(opts={}) inject({}) do |new_hash, (k,v)| if !v.blank? new_hash[k] = opts[:recurse] && v.class == Hash ? v.compact_blank(opts) : v end new_hash end end | 
#to_hash_recursive ⇒ Object
| 6 7 8 9 10 11 12 13 14 15 16 | # File 'lib/ky/hash.rb', line 6 def to_hash_recursive result = self.to_h result.each do |key, value| if(value.kind_of? Hash) result[key] = value.to_hash_recursive.to_h elsif (value.kind_of? Array) result[key] = value.map { |item| item.kind_of?(Hash) ? item.to_hash_recursive : item } end end result end | 
#to_plain_yaml(opts = {}) ⇒ Object
which yields ugly !map:ActiveSupport::HashWithIndifferentAccess
| 2 3 4 | # File 'lib/ky/hash.rb', line 2 def to_plain_yaml(opts = {}) # which yields ugly !map:ActiveSupport::HashWithIndifferentAccess self.to_hash_recursive.to_yaml(opts) end |