Sha256: ebb213c44298addfac769d4cd51f160876d285dbf3b0e2e3af2378c558b89822

Contents?: true

Size: 1.29 KB

Versions: 23

Compression:

Stored size: 1.29 KB

Contents

class Hash # :nodoc:

  def except(*items) # :nodoc:
    self.dup.except!(*items)
  end unless method_defined?(:except)

  def except!(*keys) # :nodoc:
    copy = self.dup
    keys.each { |key| copy.delete!(key) }
    copy
  end unless method_defined?(:except!)

  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

23 entries across 23 versions & 1 rubygems

Version Path
github_api-0.7.1 lib/github_api/core_ext/hash.rb
github_api-0.7.0 lib/github_api/core_ext/hash.rb
github_api-0.6.5 lib/github_api/core_ext/hash.rb
github_api-0.6.4 lib/github_api/core_ext/hash.rb
github_api-0.6.3 lib/github_api/core_ext/hash.rb
github_api-0.6.2 lib/github_api/core_ext/hash.rb
github_api-0.6.1 lib/github_api/core_ext/hash.rb
github_api-0.6.0 lib/github_api/core_ext/hash.rb
github_api-0.5.4 lib/github_api/core_ext/hash.rb
github_api-0.5.3 lib/github_api/core_ext/hash.rb
github_api-0.5.2 lib/github_api/core_ext/hash.rb
github_api-0.5.1 lib/github_api/core_ext/hash.rb
github_api-0.5.0 lib/github_api/core_ext/hash.rb
github_api-0.5.0.rc1 lib/github_api/core_ext/hash.rb
github_api-0.4.11 lib/github_api/core_ext/hash.rb
github_api-0.4.10 lib/github_api/core_ext/hash.rb
github_api-0.4.9 lib/github_api/core_ext/hash.rb
github_api-0.4.8 lib/github_api/core_ext/hash.rb
github_api-0.4.7 lib/github_api/core_ext/hash.rb
github_api-0.4.6 lib/github_api/core_ext/hash.rb