Sha256: 7b6769a4fee403308f73306f6d39103543db6c55b6f12f50fb5925b57c50a7c7

Contents?: true

Size: 924 Bytes

Versions: 1

Compression:

Stored size: 924 Bytes

Contents

# Override Hash class with convience methods
class Hash

  def self.transform_keys_to_symbols(value)
    return value if not value.is_a?(Hash)
    hash = value.inject({}){|memo,(k,v)| memo[k.to_sym] = Hash.transform_keys_to_symbols(v); memo}
    return hash
  end

  # Take keys of hash and transform those to a symbols
  def transform_keys_to_symbols
    inject({}){|memo, (k, v)| memo[k.to_sym] = Hash.transform_keys_to_symbols(v); memo}
  end

  # Value present in nested Hash
  def include_value?(value)
    each_value do |v|
      return true if v == value
      next unless v.is_a? Hash
      v.each_value do |v|
        return true if v == value
      end
    end
    false
  end

  def include_key?(key)
    each do |k, v|
      return true if k == key
      next unless v.is_a? Hash
      v.each do |k, v|
        return true if k == key
      end
    end
    false
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
soaspec-0.0.7 lib/soaspec/hash_methods.rb