Class Hashery::CastingHash
In: lib/hashery/casting_hash.rb
Parent: CRUDHash

CastingHash is just like CRUDHash, except that both keys and values can be passed through casting procedures.

Methods

[]   cast_proc   cast_proc=   new   recast!   replace   store   to_h   to_hash  

Public Class methods

Like `new` but can take a priming Hash or Array-pairs.

hash - Hash-like object.

Examples

  CastingHash[:a,1,:b,2]

Returns `CastingHash`.

Unlike traditional Hash a CastingHash‘s block argument coerces key/value pairs when store is called.

default - Default value. cast_proc - Casting procedure.

Public Instance methods

The cast procedure.

proc - Casting procedure.

Returns `Proc` used for casting.

Set `cast_proc`. This procedure must take two arguments (`key, value`) and return the same.

proc - Casting procedure.

Returns proc.

Recast all entries via the cast procedure.

TODO: Isn‘t this the same as `rehash`?

Returns self.

Replace current entries with those from another Hash, or Hash-like object. Each entry is run through the casting procedure as it is added.

other - Hash-like object.

Returns self.

CRUD method for create and update. Unlike the parent class the key, value pair are passed threw the cast_proc before being set in the underlying hash table.

key - Key of entry. value - Value of entry.

Returns the value.

to_h()

Alias for to_hash

Convert the CastingHash to a regular Hash.

Returns an ordinary `Hash`.

[Validate]