Class Hashery::OpenHash
In: lib/hashery/open_hash.rb
Parent: CRUDHash

OpenHash is a Hash, but also supports open properties much like OpenStruct.

Only names that are name methods of Hash can be used as open slots. To open a slot for a name that would otherwise be a method, the method needs to be made private. The `open!` method can be used to handle this.

Examples

    o = OpenHash.new
    o.open!(:send)
    o.send = 4

Methods

close!   method_missing   new   omit!   open!   open?   store  

External Aliases

class -> object_class

Attributes

safe  [RW]  If safe is set to true, then public methods cannot be overriden by hash keys.

Public Class methods

Initialize new OpenHash instance.

TODO: Maybe `safe` should be the first argument?

Public Instance methods

Make specific Hash methods available for use that have previously opened.

methods - [Array<String,Symbol>] method names

Returns methods.

omit!(*methods)

Alias for open!

Open up a slot that that would normally be a Hash method.

The only methods that can‘t be opened are ones starting with `__`.

methods - [Array<String,Symbol>] method names

Returns Array of slot names that were opened.

Is a slot open?

method - [String,Symbol] method name

Returns `true` or `false`.

Index `value` to `key`. Unless safe mode, will also open up the key if it is not already open.

key - Index key to associate with value. value - Value to be associate with key.

Returns value.

[Validate]