class

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

CHAINED_HASH_METHODS = ["reject!", "select!", "compact!", "clear"] of ::String

List of methods delegated to the underlying Hash returning self.

VERSION = {{ (`shards version \"/tmp/tmp.KmchEB/src/src/any_hash\"`).chomp.stringify }}

Constructors

new(hash = nil)

Initializes AnyHash with the given hash object.

NOTE: AnyHash | Hash objects are passed by reference.

Source

Class methods

deep_cast_value(value)

Deep casts value to the V type.

ameba:disable Metrics/CyclomaticComplexity

Source

Instance methods

==(other : self)

ditto

Source
==(other : NamedTuple)

ditto

Source
==(*args, **options)

See Hash#==.

Source
==(*args, **options, &)

See Hash#==.

Source
===(*args, **options)

See Hash#==.

Source
===(*args, **options, &)

See Hash#==.

Source
[](*keys)

See #dig.

Source
[]=(key, value)

See Hash#[]=.

Source
[]=(*args)

See Hash#[]=.

Source
[]?(*keys)

See #dig?.

Source
clone

Returns a new AnyHash, with a deep copy of the underlying Hash.

Use #dup if you want a shallow copy.

Source
dig(keys : Enumerable)

Extracts the nested value specified by the sequence of keys objects by calling #[] at each step, raises if any intermediate step is nil.

Source
dig(*keys)

ditto

Source
dig?(keys : Enumerable)

Extracts the nested value specified by the sequence of keys objects by calling #[]? at each step, returns nil if any intermediate step is nil.

Source
dig?(*keys)

ditto

Source
dup

Returns a new AnyHash, with a shallow copy of the underlying Hash.

Use #clone if you want a deep copy.

Source
each(*args, **options)

See Hash#each.

Source
each(*args, **options, &)

See Hash#each.

Source
merge(*values, **options)

Performs deep merge of self with given other values and returns copy of self.

See Hash#merge.

Source
merge(*values, **options, &)

ditto

Source
merge!(*values, **options)

Destructive version of #merge.

Source
merge!(*values, **options, &)

ditto

Source
replace(other)

Replaces underlying Hash with given other.

Returns self.

Source
reverse_merge(other = nil, *values, **options)

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.

Source
reverse_merge(other = nil, *values, **options, &)

ditto

Source
reverse_merge!(other = nil, *values, **options)

Destructive version of #reverse_merge.

Source
reverse_merge!(other = nil, *values, **options, &)

ditto

Source
to_h(*args, **options)

See Hash#to_h.

Source
to_h(*args, **options, &)

See Hash#to_h.

Source

Macros

define_new(klass, key, value)

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.

Source
method_missing(call)
Source

Nested types