module Hash::Wrapper(K, V)

Overview

Wraps a Hash object. The including type will behave as a read-only hash, where objects returned by methods will be wrapped as well if the return type is the same as the original hash.

class Table
  include HashWrapper(String, Int32)
end

table = Table.new({"a" => 1, "b" => 2})
table["a"]?                   # => 1
table["b"]?                   # => 2
table["c"]?                   # => nil
table["c"] = 3                # does not compile
table.select { |_, v| v > 2 } # => Table{"b" => 2}

Included Modules

Direct including types

Defined in:

views/hash_wrapper.cr

Constructors

Instance Method Summary

Instance methods inherited from module Wrapper(Hash(K, V))

==(rhs : T(K, V)) : Bool
==(rhs : self) : Bool
==
, pretty_print(*args, **options)
pretty_print(*args, **options, &)
pretty_print
, to_s(*args, **options)
to_s(*args, **options, &)
to_s
, wrapped : T(K, V) wrapped

Constructor methods inherited from module Wrapper(Hash(K, V))

new(wrapped : T(K, V) = T.new) new

Constructor Detail

def self.new(wrapped : Hash(K, V) = {} of K => V) #

[View source]

Instance Method Detail

def [](*args, **options) #

[View source]
def [](*args, **options, &) #

[View source]
def []?(*args, **options) #

[View source]
def []?(*args, **options, &) #

[View source]
def compact(*args, **options) #

[View source]
def compact(*args, **options, &) #

[View source]
def dig(*args, **options) #

[View source]
def dig(*args, **options, &) #

[View source]
def dig?(*args, **options) #

[View source]
def dig?(*args, **options, &) #

[View source]
def each(*args, **options) #

[View source]
def each(*args, **options, &) #

[View source]
def each_key(*args, **options) #

[View source]
def each_key(*args, **options, &) #

[View source]
def each_value(*args, **options) #

[View source]
def each_value(*args, **options, &) #

[View source]
def empty?(*args, **options) #

[View source]
def empty?(*args, **options, &) #

[View source]
def fetch(*args, **options) #

[View source]
def fetch(*args, **options, &) #

[View source]
def first_key(*args, **options) #

[View source]
def first_key(*args, **options, &) #

[View source]
def first_key?(*args, **options) #

[View source]
def first_key?(*args, **options, &) #

[View source]
def first_value(*args, **options) #

[View source]
def first_value(*args, **options, &) #

[View source]
def first_value?(*args, **options) #

[View source]
def first_value?(*args, **options, &) #

[View source]
def has_key?(*args, **options) #

[View source]
def has_key?(*args, **options, &) #

[View source]
def has_value?(*args, **options) #

[View source]
def has_value?(*args, **options, &) #

[View source]
def inspect(io : IO) : Nil #

[View source]
def invert(*args, **options) #

[View source]
def invert(*args, **options, &) #

[View source]
def key_for(*args, **options) #

[View source]
def key_for(*args, **options, &) #

[View source]
def key_for?(*args, **options) #

[View source]
def key_for?(*args, **options, &) #

[View source]
def keys(*args, **options) #

[View source]
def keys(*args, **options, &) #

[View source]
def last_key(*args, **options) #

[View source]
def last_key(*args, **options, &) #

[View source]
def last_key?(*args, **options) #

[View source]
def last_key?(*args, **options, &) #

[View source]
def last_value(*args, **options) #

[View source]
def last_value(*args, **options, &) #

[View source]
def last_value?(*args, **options) #

[View source]
def last_value?(*args, **options, &) #

[View source]
def merge(*args, **options) #

[View source]
def merge(*args, **options, &) #

[View source]
def proper_subset_of?(*args, **options) #

[View source]
def proper_subset_of?(*args, **options, &) #

[View source]
def proper_superset_of?(*args, **options) #

[View source]
def proper_superset_of?(*args, **options, &) #

[View source]
def reject(*args, **options) #

[View source]
def reject(*args, **options, &) #

[View source]
def select(*args, **options) #

[View source]
def select(*args, **options, &) #

[View source]
def size(*args, **options) #

[View source]
def size(*args, **options, &) #

[View source]
def subset_of?(*args, **options) #

[View source]
def subset_of?(*args, **options, &) #

[View source]
def superset_of?(*args, **options) #

[View source]
def superset_of?(*args, **options, &) #

[View source]
def to_a(*args, **options) #

[View source]
def to_a(*args, **options, &) #

[View source]
def to_h : Hash(K, V) #

Returns the wrapped hash.


[View source]
def to_s(*args, **options) #

[View source]
def to_s(*args, **options, &) #

[View source]
def transform_keys(*args, **options) #

[View source]
def transform_keys(*args, **options, &) #

[View source]
def transform_values(*args, **options) #

[View source]
def transform_values(*args, **options, &) #

[View source]
def values(*args, **options) #

[View source]
def values(*args, **options, &) #

[View source]
def values_at(*args, **options) #

[View source]
def values_at(*args, **options, &) #

[View source]