struct Hash::View(K, V)

Overview

A HashView is a read-only version of a Hash. This is useful to give access to a non-modifiable hash in a type-safe manner.

The functionality of HashView is limited by design, as it just delegates the non-writable methods to the enclosed hash.

arr = HashView.new({"a" => 1, "b" => 2})
arr.size        # => 2
arr["a"]        # => 1
arr.select "b"  # => {"b" => 2}
arr.select! "b" # does not compile
arr["c"] = 3    # does not compile

Included Modules

Defined in:

views/hash_view.cr

Constructors

Instance Method Summary

Constructor Detail

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

[View source]

Instance Method Detail

def ==(rhs : Hash(K, V)) : Bool #

[View source]
def ==(rhs : self) : Bool #

[View source]
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 #
Description copied from struct Struct

Appends this struct's name and instance variables names and values to the given IO.

struct Point
  def initialize(@x : Int32, @y : Int32)
  end
end

p1 = Point.new 1, 2
p1.to_s    # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"

[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 pretty_print(*args, **options) #

[View source]
def pretty_print(*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(*args, **options) #

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

[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]