Class PropertyHash
In: lib/hashery/propertyhash.rb
Parent: Hash

A PropertyHash is the same as a regular Hash except it strictly limits the allowed keys.

There are two ways to use it.

1) As an object in itself.

  h = PropertyHash.new(:a=>1, :b=>2)
  h[:a]        #=> 1
  h[:a] = 3
  h[:a]        #=> 3

But if we try to set key that was not fixed, then we will get an error.

  h[:x] = 5    #=> ArgumentError

2) As a superclass.

  class MyPropertyHash < PropertyHash
    property :a, :default => 1
    property :b, :default => 2
  end

  h = MyPropertyHash.new
  h[:a]        #=> 1
  h[:a] = 3
  h[:a]        #=> 3

Again, if we try to set key that was not fixed, then we will get an error.

  h[:x] = 5    #=> ArgumentError

Methods

<<   []=   accept_key!   merge!   new   properties   property   update  

Public Class methods

Public Instance methods

Add a new acceptable key. TODO: Should this be supported?

[Validate]