AnyHash(K, V)
Inherits Iterable < Enumerable < Reference < Object
Recursive wrapper for Hash(K, V).
Holds the given V values alone or recursively inside of a
container type like Array, Set or another Hash.
NOTE: Performs deep cast of container types:
Array→Array(V)Tuple→Array(V)Set→Set(V)NamedTuple→Hash(K, V)Hash→Hash(K, V)AnyHash→Hash(K, V)
Constants
List of methods delegated to the underlying Hash returning self.
Constructors
Initializes AnyHash with the given hash object.
NOTE: AnyHash | Hash objects are passed by reference.
Class methods
Deep casts value to the V type.
ameba:disable Metrics/CyclomaticComplexity
Instance methods
Returns a new AnyHash, with a deep copy of the underlying Hash.
Use #dup if you want a shallow copy.
Extracts the nested value specified by the sequence of keys objects
by calling #[] at each step, raises
if any intermediate step is nil.
Extracts the nested value specified by the sequence of keys objects
by calling #[]? at each step, returns nil
if any intermediate step is nil.
Returns a new AnyHash, with a shallow copy of the underlying Hash.
Use #clone if you want a deep copy.
Performs deep merge of self with given other values
and returns copy of self.
See Hash#merge.
Merges the caller into other. For example,
options = options.reverse_merge(size: 25, velocity: 10)
is equivalent to
options = { size: 25, velocity: 10 }.merge(options)
This is particularly useful for initializing an options hash with default values.
Macros
Defines new klass klass inheriting from AnyHash
with given key keys and recursive value types.
AnyHash.define_new klass: :StringHash,
key: String,
value: String | Symbol
StringHash::Key # => String
StringHash::Value # => String | Symbol
StringHash.new({"foo" => {:bar, "baz"}})
# => #<StringHash:0x100d5e180 @__hash__={"foo" => [:bar, "baz"]}>
See AnyHash.