class
Hamilton::Storage
- Hamilton::Storage
- Reference
- Object
Overview
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.
Defined in:
storage.crConstructors
-
.new
Create an empty
Hamilton::Storage.
Instance Method Summary
-
#[](key : Symbol)
Get value for the
key. -
#[]=(key : Symbol, value)
Assignes
valueto akey. -
#[]?(key : Symbol)
Get value for the
key, or nil if it doesn't exist. -
#clear : self
Empties the storage and returns it.
-
#delete(key : Symbol)
Deletes the key-value pair and returns the value, otherwise returns
nil. -
#delete(key : Symbol, & : Symbol -> )
Deletes the key-value pair and returns the value, else yields key with given block.
- #each(&block : Tuple(Symbol, Hamilton::Any) -> ) : Nil
-
#empty?
Returns
truewhen hash contains no key-value pairs. -
#fetch(key : Symbol, default)
Returns the value for the
key, or when not found the value given bydefault. -
#fetch(key : Symbol, &)
Returns the value for the
key, or when not found the value returned by the given block invoked withkey. -
#has_key?(key : Symbol)
Check if there is a key in the storage.
-
#keys
Get all keys in the storage.
-
#put(key : Symbol, value, &)
Tries to set
valueto akey. -
#put_if_absent(key : Symbol, value)
Tries to set
valueto akeyif it's absent yet. -
#put_if_absent(key : Symbol, & : Symbol -> )
Tries to set the result of the given block to a
keyif it's absent yet. -
#size
Get size of the storage.
-
#to_a
Returns an
ArrayofTuple(Symbol, Hamilton::Any)with keys and values belonging to this Storage. -
#values
Get all values in the storage.
Instance methods inherited from class Reference
==(other : Hamilton::Any)
==
Instance methods inherited from class Object
===(other : Hamilton::Any)
===
Constructor Detail
Instance Method Detail
Assignes value to a key. Raises an ArgumentError if something goes wrong (wrong type of value).
Deletes the key-value pair and returns the value, else yields key with given block.
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).
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).
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.
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.
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.
Returns an Array of Tuple(Symbol, Hamilton::Any) with keys and values belonging to this Storage.