Sha256: ae7ed7c601f485fa35362ea8dbc3fceb1bab379379c101751b0d222a78dffc45

Contents?: true

Size: 1.14 KB

Versions: 9

Compression:

Stored size: 1.14 KB

Contents

class Hash # :nodoc:

  def symbolize_keys  # :nodoc:
    inject({}) do |hash, (key, value)|
      hash[(key.to_sym rescue key) || key] = value
      hash
    end
  end unless method_defined?(:symbolize_keys)

  def symbolize_keys! # :nodoc:
    hash = symbolize_keys
    hash.each do |key, val|
      hash[key] = case val
                  when Hash
                    val.symbolize_keys!
                  when Array
                    val.map do |item|
                      item.is_a?(Hash) ? item.symbolize_keys! : item
                    end
                  else
                    val
                  end
    end
    return hash
  end unless method_defined?(:symbolize_keys!)

  def serialize # :nodoc:
    self.map { |key, val| [key, val].join("=") }.join("&")
  end unless method_defined?(:serialize)

  def all_keys # :nodoc:
    keys = self.keys
    keys.each do |key|
      if self[key].is_a?(Hash)
        keys << self[key].all_keys.compact.flatten
        next
      end
    end
    keys.flatten
  end unless method_defined?(:all_keys)

  def has_deep_key?(key)
    self.all_keys.include? key
  end unless method_defined?(:has_deep_key?)

end # Hash

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
zz_bitbucket_rest_api-0.1.11 lib/bitbucket_rest_api/core_ext/hash.rb
zz_bitbucket_rest_api-0.1.10 lib/bitbucket_rest_api/core_ext/hash.rb
zz_bitbucket_rest_api-0.1.9 lib/bitbucket_rest_api/core_ext/hash.rb
zz_bitbucket_rest_api-0.1.8 lib/bitbucket_rest_api/core_ext/hash.rb
bitbucket_rest_api2-0.9.5 lib/bitbucket_rest_api/core_ext/hash.rb
bitbucket_rest_api2-0.9.1 lib/bitbucket_rest_api/core_ext/hash.rb
bitbucket_rest_api2-0.2.2 lib/bitbucket_rest_api/core_ext/hash.rb
bitbucket_rest_api2-0.2.1 lib/bitbucket_rest_api/core_ext/hash.rb
bitbucket_rest_api2-0.2.0 lib/bitbucket_rest_api/core_ext/hash.rb