class Hash

Public Instance Methods

compact_blank(opts={}) click to toggle source
# 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() click to toggle source
# 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 = {}) click to toggle source
# 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