class

Hamilton::Storage

Inherits Reference < Object

Storage class for Hamilton::Context. Basically, it's a hidden Hash(Symbol, Hamilton::Any) with some methods being overridden (same behavior as in Hash) without the need for explicit convertion values to Hamilton::Any.

Constructors

new

Create an empty Hamilton::Storage.

Source

Instance methods

[](key : Symbol)

Get value for the key. If key does not exist, raises a KeyError exception.

Source
[]=(key : Symbol, value)

Assignes value to a key. Raises an ArgumentError if something goes wrong (wrong type of value).

Source
[]?(key : Symbol)

Get value for the key, or nil if it doesn't exist.

Source
clear

Empties the storage and returns it.

Source
delete(key : Symbol)

Deletes the key-value pair and returns the value, otherwise returns nil.

Source
delete(key : Symbol, & : Symbol -> )

Deletes the key-value pair and returns the value, else yields key with given block.

Source
each
Source
empty?

Returns true when hash contains no key-value pairs.

Source
fetch(key : Symbol, default)

Returns the value for the key, or when not found the value given by default. Raises an ArgumentError if something goes wrong (wrong type of default).

Source
fetch(key : Symbol, &)

Returns the value for the key, or when not found the value returned by the given block invoked with key. Raises an ArgumentError if something goes wrong (wrong type of block's result).

Source
has_key?(key : Symbol)

Check if there is a key in the storage.

Source
keys

Get all keys in the storage.

Source
put(key : Symbol, value, &)

Tries to set value to a key. Raises an ArgumentError if something goes wrong (wrong type of value).

If a value already exists for key, that (old) value is returned. Otherwise the given block is invoked with key and its value is returned.

Source
put_if_absent(key : Symbol, value)

Tries to set value to a key if it's absent yet. Raises an ArgumentError if something goes wrong (wrong type of value).

If a value already exists for key, that (old) value is returned. Otherwise value is returned.

Source
put_if_absent(key : Symbol, & : Symbol -> )

Tries to set the result of the given block to a key if it's absent yet. Raises an ArgumentError if something goes wrong (wrong type of block's result).

If a value already exists for key, that (old) value is returned. Otherwise the given block is invoked with key and its value is returned.

Source
size

Get size of the storage.

Source
to_a

Returns an Array of Tuple(Symbol, Hamilton::Any) with keys and values belonging to this Storage.

Source
values

Get all values in the storage.

Source