Sha256: 37902d7c83374c7cb1ccbecea78463af5fe8be02293ce221d9c0562361eb832e

Contents?: true

Size: 785 Bytes

Versions: 8

Compression:

Stored size: 785 Bytes

Contents

class Hash

  ##
  # Create a hash with *only* key/value pairs in receiver and +allowed+
  #
  #   { :one => 1, :two => 2, :three => 3 }.only(:one)    #=> { :one => 1 }
  #
  # @param [Array[String, Symbol]] *allowed The hash keys to include.
  #
  # @return [Hash] A new hash with only the selected keys.
  #
  # @api public
  def only(*allowed)
    hash = {}
    allowed.each {|k| hash[k] = self[k] if self.has_key?(k) }
    hash
  end

  # Convert to Mash. This class has semantics of ActiveSupport's
  # HashWithIndifferentAccess and we only have it so that people can write
  # params[:key] instead of params['key'].
  #
  # @return [Mash] This hash as a Mash for string or symbol key access.
  def to_mash
    hash = Mash.new(self)
    hash.default = default
    hash
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dm-core-1.1.0.rc2 lib/dm-core/core_ext/hash.rb
dm-core-1.1.0.rc1 lib/dm-core/core_ext/hash.rb
dm-core-1.0.2 lib/dm-core/core_ext/hash.rb
dm-core-1.0.1 lib/dm-core/core_ext/hash.rb
dm-core-1.0.0 lib/dm-core/core_ext/hash.rb
dm-core-1.0.0.rc3 lib/dm-core/core_ext/hash.rb
dm-core-1.0.0.rc2 lib/dm-core/core_ext/hash.rb
dm-core-1.0.0.rc1 lib/dm-core/core_ext/hash.rb