struct Hash::View(K, V)
- Hash::View(K, V)
- Struct
- Value
- Object
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
- Enumerable({K, V})
- Iterable({K, V})
Defined in:
views/hash_view.crConstructors
Instance Method Summary
- #==(rhs : Hash(K, V)) : Bool
- #==(rhs : self) : Bool
- #[](*args, **options)
- #[](*args, **options, &)
- #[]?(*args, **options)
- #[]?(*args, **options, &)
- #compact(*args, **options)
- #compact(*args, **options, &)
- #dig(*args, **options)
- #dig(*args, **options, &)
- #dig?(*args, **options)
- #dig?(*args, **options, &)
- #each(*args, **options)
- #each(*args, **options, &)
- #each_key(*args, **options)
- #each_key(*args, **options, &)
- #each_value(*args, **options)
- #each_value(*args, **options, &)
- #empty?(*args, **options)
- #empty?(*args, **options, &)
- #fetch(*args, **options)
- #fetch(*args, **options, &)
- #first_key(*args, **options)
- #first_key(*args, **options, &)
- #first_key?(*args, **options)
- #first_key?(*args, **options, &)
- #first_value(*args, **options)
- #first_value(*args, **options, &)
- #first_value?(*args, **options)
- #first_value?(*args, **options, &)
- #has_key?(*args, **options)
- #has_key?(*args, **options, &)
- #has_value?(*args, **options)
- #has_value?(*args, **options, &)
-
#inspect(io : IO) : Nil
Appends this struct's name and instance variables names and values to the given IO.
- #invert(*args, **options)
- #invert(*args, **options, &)
- #key_for(*args, **options)
- #key_for(*args, **options, &)
- #key_for?(*args, **options)
- #key_for?(*args, **options, &)
- #keys(*args, **options)
- #keys(*args, **options, &)
- #last_key(*args, **options)
- #last_key(*args, **options, &)
- #last_key?(*args, **options)
- #last_key?(*args, **options, &)
- #last_value(*args, **options)
- #last_value(*args, **options, &)
- #last_value?(*args, **options)
- #last_value?(*args, **options, &)
- #merge(*args, **options)
- #merge(*args, **options, &)
- #pretty_print(*args, **options)
- #pretty_print(*args, **options, &)
- #proper_subset_of?(*args, **options)
- #proper_subset_of?(*args, **options, &)
- #proper_superset_of?(*args, **options)
- #proper_superset_of?(*args, **options, &)
- #reject(*args, **options)
- #reject(*args, **options, &)
- #select(*args, **options)
- #select(*args, **options, &)
- #size(*args, **options)
- #size(*args, **options, &)
- #subset_of?(*args, **options)
- #subset_of?(*args, **options, &)
- #superset_of?(*args, **options)
- #superset_of?(*args, **options, &)
- #to_a(*args, **options)
- #to_a(*args, **options, &)
- #to_h(*args, **options)
- #to_h(*args, **options, &)
- #to_s(*args, **options)
- #to_s(*args, **options, &)
- #transform_keys(*args, **options)
- #transform_keys(*args, **options, &)
- #transform_values(*args, **options)
- #transform_values(*args, **options, &)
- #values(*args, **options)
- #values(*args, **options, &)
- #values_at(*args, **options)
- #values_at(*args, **options, &)
Constructor Detail
Instance Method Detail
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)"