Class Index [+]

Quicksearch

DataMapper::Ext::Hash

Public Class Methods

except(hash, *keys) click to toggle source

Returns a hash that includes everything but the given keys.

@param [Hash] hash The hash from which to pick the key/value pairs. @param [Array] *keys The hash keys to exclude.

@return [Hash] A new hash without the specified keys.

@example

  hash = { :one => 1, :two => 2, :three => 3 }
  Ext::Hash.except(hash, :one, :two) # => { :three => 3 }

@api semipublic

    # File lib/dm-core/support/ext/hash.rb, line 33
33:     def self.except(hash, *keys)
34:       self.except!(hash.dup, *keys)
35:     end
except!(hash, *keys) click to toggle source

Removes the specified keys from the given hash.

@param [Hash] hash The hash to modify. @param [Array] *keys The hash keys to exclude.

@return [Hash] hash

@example

  hash = { :one => 1, :two => 2, :three => 3 }
  Ext::Hash.except!(hash, :one, :two)
  hash # => { :three => 3 }

@api semipublic

    # File lib/dm-core/support/ext/hash.rb, line 50
50:     def self.except!(hash, *keys)
51:       keys.each { |key| hash.delete(key) }
52:       hash
53:     end
only(hash, *keys) click to toggle source

Creates a hash with only the specified key/value pairs from hash.

@param [Hash] hash The hash from which to pick the key/value pairs. @param [Array] *keys The hash keys to include.

@return [Hash] A new hash with only the selected keys.

@example

  hash = { :one => 1, :two => 2, :three => 3 }
  Ext::Hash.only(hash, :one, :two) # => { :one => 1, :two => 2 }

@api semipublic

    # File lib/dm-core/support/ext/hash.rb, line 15
15:     def self.only(hash, *keys)
16:       h = {}
17:       keys.each {|k| h[k] = hash[k] if hash.has_key?(k) }
18:       h
19:     end
to_mash(hash) click to toggle source

Converts the specified hash to a {Mash}.

@param [Hash] hash The hash to convert. @return [Mash] The {Mash} for the specified hash.

@api semipublic

    # File lib/dm-core/support/ext/hash.rb, line 61
61:     def self.to_mash(hash)
62:       h = Mash.new(hash)
63:       h.default = hash.default
64:       h
65:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.