Class: Mash

Class | Mash
In: | lib/extlib/mash.rb
Parent: | Hash

This class has dubious semantics and we only have it so that people can write params[:key] instead of params[‘key’].

### Methods

[]= convert_key convert_value default except fetch key? merge new stringify_keys! symbolize_keys to_hash update values_at

### External Aliases

[]= | -> | regular_writer

### Public Class methods

new(constructor = {})

@param constructor<Object>

      The default value for the mash. Defaults to an empty hash.

@details [Alternatives]

      If constructor is a Hash, a new mash will be created based on the keys of
      the hash and no default value will be set.

### Public Instance methods

[]=(key, value)

@param key<Object> The key to set. @param value<Object>

      The value to set the key to.

@see Mash#convert_key @see Mash#convert_value

default(key = nil)

@param key<Object> The default value for the mash. Defaults to nil.

@details [Alternatives]

      If key is a Symbol and it is a key in the mash, then the default value will
      be set to the value matching the key.

except(*keys)

@param *rejected<Array[(String, Symbol)] The mash keys to exclude.

@return <Mash> A new mash without the selected keys.

@example

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

fetch(key, *extras)

@param key<Object> The key to fetch. This will be run through convert_key. @param *extras<Array> Default value.

@return <Object> The value at key or the default value.

key?(key)

@param key<Object> The key to check for. This will be run through convert_key.

@return <TrueClass, FalseClass> True if the key exists in the mash.

merge(hash)

@param hash<Hash> The hash to merge with the mash.

@return <Mash> A new mash with the hash values merged in.

stringify_keys!()

Used to provide the same interface as Hash.

@return <Mash> This mash unchanged.

symbolize_keys()

@return <Hash> The mash as a Hash with symbolized keys.

to_hash()

@return <Hash> The mash as a Hash with string keys.

update(other_hash)

@param other_hash<Hash>

      A hash to update values in the mash with. The keys and the values will be
      converted to Mash format.

@return <Mash> The updated mash.

values_at(*indices)

@param *indices<Array>

      The keys to retrieve values for. These will be run through +convert_key+.

@return <Array> The values at each of the provided keys

### Protected Instance methods

convert_key(key)

@param key<Object> The key to convert.

@param <Object>

      The converted key. If the key was a symbol, it will be converted to a
      string.

@api private

convert_value(value)

@param value<Object> The value to convert.

@return <Object>

      The converted value. A Hash or an Array of hashes, will be converted to
      their Mash equivalents.

@api private

[Validate]