- README

- Top Level Namespace
- Adler32
- ArgumentError
- Array
- Atomic
- Base64
  - Error
- Benchmark
  - BM
    - Job
    - Tms
  - IPS
    - Entry
    - Job
- BigFloat
- BigInt
- BigRational
- BitArray
- Bool
- Box
- Bytes
- Channel
  - Buffered
  - ClosedError
  - ReceiveAction
  - SelectAction
  - SendAction
  - Unbuffered
- Char
  - Reader
- Class
- Colorize
  - Object
  - ObjectExtensions
- Comparable
- Complex
- Concurrent
  - CanceledError
- CRC32
- Crypto
  - Bcrypt
    - Error
    - Password
  - Blowfish
  - Subtle
- CSV
  - Builder
    - Row
  - Error
  - Lexer
  - MalformedCSVError
  - Parser
  - Row
  - Token
    - Kind
- Debug
  - DWARF
    - Abbrev
      - Attribute
    - AT
    - FORM
    - Info
      - Value
    - LineNumbers
      - Register
      - Row
      - Sequence
    - LNE
    - LNS
    - Strings
    - TAG
  - ELF
    - Endianness
    - Error
    - Ident
    - Klass
    - Machine
    - OSABI
    - SectionHeader
      - Flags
      - Type
    - Type
- Deque
- Digest
  - Base
  - MD5
  - SHA1
- Dir
- DivisionByZero
- DL
- ECR
- Enum
- Enumerable
  - EmptyError
- ENV
- Errno
- Exception
- Fiber
- File
  - Stat
- FileUtils
- Flate
  - Error
  - Reader
  - Strategy
  - Writer
- Float
  - Primitive
- Float32
- Float64
- GC
  - Stats
- Gzip
  - Error
  - Header
  - Reader
  - Writer
- Hash
- HTML
- HTTP
  - Client
    - BodyType
    - Response
  - CompressHandler
  - ComputedContentTypeHeader
  - Cookie
  - Cookies
  - ErrorHandler
  - FormData
    - Builder
    - Error
    - FileMetadata
    - Parser
    - Part
  - Handler
    - Proc
  - Headers
  - LogHandler
  - Multipart
    - Builder
    - Error
    - Parser
  - Params
    - Builder
  - Request
  - Server
    - Context
    - RequestProcessor
    - Response
  - StaticFileHandler
    - DirectoryListing
  - WebSocket
  - WebSocketHandler
- Indexable
- IndexError
- INI
- Int
  - Primitive
  - Signed
  - Unsigned
- Int16
- Int32
- Int64
- Int8
- InvalidByteSequenceError
- IO
  - Buffered
  - ByteFormat
    - BigEndian
    - LittleEndian
    - NetworkEndian
    - SystemEndian
  - Delimited
  - EncodingOptions
  - EOFError
  - Error
  - FileDescriptor
  - Hexdump
  - Memory
  - MultiWriter
  - Seek
  - Sized
  - Timeout
- IPSocket
- Iterable
- Iterator
  - IteratorWrapper
  - Stop
- JSON
  - Any
  - Builder
    - ArrayState
    - DocumentEndState
    - DocumentStartState
    - ObjectState
    - StartState
    - State
  - Error
  - Lexer
  - ParseException
  - Parser
  - PullParser
  - Token
  - Type
- KeyError
- Levenshtein
  - Finder
- LLVM
  - ABI
    - AArch64
    - ArgKind
    - ArgType
    - ARM
    - FunctionType
    - X86
    - X86_64
      - RegClass
  - AtomicOrdering
  - AtomicRMWBinOp
  - Attribute
  - AttributeIndex
  - BasicBlock
  - BasicBlockCollection
  - Builder
  - CallConvention
  - CodeGenFileType
  - CodeGenOptLevel
  - CodeModel
  - Context
  - DIBuilder
  - DIFlags
  - DwarfTag
  - DwarfTypeEncoding
  - Function
  - FunctionCollection
  - FunctionPassManager
    - Runner
  - GenericValue
  - GlobalCollection
  - InstructionCollection
  - IntPredicate
  - JITCompiler
  - Linkage
  - MemoryBuffer
  - Module
  - ModuleFlag
  - ModulePassManager
  - ParameterCollection
  - PassManagerBuilder
  - PassRegistry
  - PhiTable
  - RealPredicate
  - RelocMode
  - Target
  - TargetData
  - TargetMachine
  - Type
    - Kind
  - Value
    - Kind
  - ValueMethods
  - VerifierFailureAction
- Logger
  - Formatter
  - Severity
- Markdown
  - HTMLRenderer
  - Parser
    - PrefixHeader
    - UnorderedList
  - Renderer
- Math
- Mutex
- NamedTuple
- Nil
- Number
  - Primitive
- OAuth
  - AccessToken
  - Consumer
  - Error
  - RequestToken
- OAuth2
  - AccessToken
    - Bearer
    - Mac
  - Client
  - Error
  - Session
- Object
- OpenSSL
  - Digest
    - Error
    - UnsupportedError
  - DigestBase
  - Error
  - HMAC
  - MD5
  - SHA1
  - SSL
    - Context
      - Client
      - Server
    - Error
    - ErrorType
    - Modes
    - Options
    - Socket
      - Client
      - Server
    - VerifyMode
    - X509VerifyFlags
- OptionParser
  - Exception
  - InvalidOption
  - MissingOption
- PartialComparable
- Pointer
  - Appender
- PrettyPrint
- Proc
- Process
  - Env
  - Status
  - Stdio
  - Tms
- Random
  - MT19937
- Range
- Readline
  - CompletionProc
  - KeyBindingProc
- Reference
- Reflect
- Regex
  - MatchData
  - Options
- SecureRandom
- Set
- Signal
- Slice
- Socket
  - Address
  - Addrinfo
  - Error
  - Family
  - IPAddress
  - Protocol
  - Server
  - Type
  - UNIXAddress
- Spec
  - Expectations
  - Methods
  - ObjectExtensions
- StaticArray
- String
  - Builder
  - RawConverter
- StringPool
- StringScanner
- Struct
- Symbol
- System
- TCPServer
- TCPSocket
- Tempfile
- Termios
  - AttributeSelection
  - BaudRate
  - ControlMode
  - InputMode
  - LineControl
  - LocalMode
  - OutputMode
- Time
  - DayOfWeek
  - EpochConverter
  - EpochMillisConverter
  - Format
    - Error
  - Kind
  - MonthSpan
  - Span
- Tuple
- TypeCastError
- UDPSocket
- UInt16
- UInt32
- UInt64
- UInt8
- Unicode
  - CaseOptions
- Union
- UNIXServer
- UNIXSocket
- URI
  - Error
- Value
- WeakRef
- XML
  - Attributes
  - AttributeType
  - Builder
  - Error
  - HTMLParserOptions
  - Namespace
  - Node
  - NodeSet
  - ParserOptions
  - Reader
  - SaveOptions
  - Type
  - XPathContext
- YAML
  - Any
  - Builder
  - Error
  - EventKind
  - ParseException
  - Parser
  - PullParser
  - Type
- Zip
  - CompressionMethod
  - Error
  - File
    - Entry
  - FileInfo
  - Reader
    - Entry
  - Writer
    - Entry
- Zlib
  - Error
  - Reader
  - Writer

# class Hash(K, V)

- Hash(K, V)
- Reference
- Object

## Overview

A `Hash` represents a mapping of keys to values.

See the official docs for the basics.

## Included Modules

- Enumerable({K, V})
- Iterable({K, V})

## Defined in:

## Class Method Summary

- .new(block : Hash(K, V), K -> V? = nil, initial_capacity = nil)
- .new(pull : YAML::PullParser, &block)
- .new(initial_capacity = nil, &block : Hash(K, V), K -> V)
- .new(default_value : V, initial_capacity = nil)
- .new(pull : JSON::PullParser)
- .new(pull : YAML::PullParser)
- .zip(ary1 : Array(K), ary2 : Array(V))

  Zips two arrays into a `Hash`, taking keys from ary1 and values from ary2.

## Instance Method Summary

- #==(other : Hash)

  Compares with other.

- #[](key)

  See also: `Hash#fetch`.

- #[]=(key : K, value : V)

  Sets the value of key to the given value.

- #[]?(key)

  Returns the value for the key given by key.

- #clear

  Empties a `Hash` and returns it.

- #clone

  Similar to `#dup`, but duplicates the values as well.

- #compact

  Returns new `Hash` without `nil` values.

- #compact!

  Removes all `nil` value from `self`.

- #delete(key)

  Deletes the key-value pair and returns the value, otherwise returns `nil`.

- #delete(key, &block)

  Deletes the key-value pair and returns the value, else yields key with given block.

- #delete_if(&block)

  Deletes each key-value pair for which the given block returns `true`.

- #dup

  Duplicates a `Hash`.

- #each

  Returns an iterator over the hash entries.

- #each(&block) : Nil

  Calls the given block for each key-value pair and passes in the key and the value.

- #each_key

  Returns an iterator over the hash keys.

- #each_key(&block)

  Calls the given block for each key-value pair and passes in the key.

- #each_value(&block)

  Calls the given block for each key-value pair and passes in the value.

- #each_value

  Returns an iterator over the hash values.

- #empty?

  Returns `true` when hash contains no key-value pairs.

- #fetch(key, &block)

  Returns the value for the key given by key, or when not found calls the given block with the key.

- #fetch(key, default)

  Returns the value for the key given by key, or when not found the value given by default.

- #fetch(key)

  Returns the value for the key given by key.

- #first_key

  Returns the first key in the hash.

- #first_key?

  Returns the first key if it exists, or returns `nil`.

- #first_value

  Returns the first value in the hash.

- #first_value?

  Similar to `#first_key?`, but returns its value.

- #has_key?(key)

  Returns `true` when key given by key exists, otherwise `false`.

- #has_value?(val)

  Returns `true` when value given by value exists, otherwise `false`.

- #hash

  See also: `Object#hash`.

- #inspect(io : IO)
- #invert

  Inverts keys and values.

- #key(value)

  Returns the first key with the given value, else raises `KeyError`.

- #key(value, &block)

  Returns the first key with the given value, else yields value with the given block.

- #key?(value)

  Returns the first key with the given value, else `nil`.

- #key_index(key)

  Returns the index of the given key, or `nil` when not found.

- #keys

  Returns a new `Array` with all the keys.

- #merge(other : Hash(L, W)) forall L, W

  Returns a new `Hash` with the keys and values of this hash and other combined.

- #merge(other : Hash(L, W), &block : K, V, W -> V | W) forall L, W
- #merge!(other : Hash)

  Similar to `#merge`, but the receiver is modified.

- #merge!(other : Hash, &block)
- #pretty_print(pp) : Nil
- #rehash
- #reject(*keys)

  Returns a new `Hash` without the given keys.

- #reject(&block : K, V -> _)

  Returns a new hash consisting of entries for which the block returns `false`.

- #reject!(&block : K, V -> _)

  Equivalent to `Hash#reject`, but makes modification on the current object rather that returning a new one.

- #reject!(keys : Array | Tuple)

  Removes a list of keys out of hash.

- #reject!(*keys)
- #select(&block : K, V -> _)

  Returns a new hash consisting of entries for which the block returns `true`.

- #select(keys : Array | Tuple)

  Returns a new `Hash` with the given keys.

- #select(*keys)
- #select!(&block : K, V -> _)

  Equivalent to `Hash#select` but makes modification on the current object rather that returning a new one.

- #select!(keys : Array | Tuple)

  Removes every element except the given ones.

- #select!(*keys)
- #shift(&block)

  Deletes and returns the first key-value pair in the hash.

- #shift

  Deletes and returns the first key-value pair in the hash, or raises `IndexError` if the hash is empty.

- #shift?

  Same as `#shift`, but returns `nil` if the hash is empty.

- #size : Int32
- #to_h

  Returns `self`.

- #to_json(json : JSON::Builder)
- #to_s(io : IO)

  Converts to a `String`.

- #to_yaml(yaml : YAML::Builder)
- #values

  Returns only the values as an `Array`.

- #values_at(*indexes : K)

  Returns a tuple populated with the elements at the given indexes.

### Instance methods inherited from module `Iterable({K, V})`

chunk(reuse = false, &block : {K, V} -> U) forall U chunk, cycle(n)
cycle cycle, each each, each_cons(count : Int, reuse = false) each_cons, each_slice(count : Int, reuse = false) each_slice, each_with_index(offset = 0) each_with_index, each_with_object(obj) each_with_object

### Instance methods inherited from module `Enumerable({K, V})`

all?(&block)
all? all?, any?(&block)
any? any?, chunks(&block : {K, V} -> U) forall U chunks, compact_map(&block) compact_map, count(&block)
count(item) count, cycle(n, &block)
cycle(&block) cycle, each(&block : {K, V} -> _) each, each_cons(count : Int, reuse = false, &block) each_cons, each_slice(count : Int, reuse = false, &block) each_slice, each_with_index(offset = 0, &block) each_with_index, each_with_object(obj, &block) each_with_object, find(if_none = nil, &block) find, first(count : Int)
first first, first? first?, flat_map(&block : {K, V} -> Array(U) | Iterator(U) | U) forall U flat_map, grep(pattern) grep, group_by(&block : {K, V} -> U) forall U group_by, in_groups_of(size : Int, filled_up_with : U = nil) forall U
in_groups_of(size : Int, filled_up_with : U = nil, reuse = false, &block) forall U in_groups_of, includes?(obj) includes?, index(&block)
index(obj) index, index_by(&block : {K, V} -> U) forall U index_by, join(separator, io)
join(separator = "")
join(separator, io, &block)
join(separator = "", &block) join, map(&block : {K, V} -> U) forall U map, map_with_index(&block : {K, V}, Int32 -> U) forall U map_with_index, max max, max? max?, max_by(&block : {K, V} -> U) forall U max_by, max_by?(&block : {K, V} -> U) forall U max_by?, max_of(&block : {K, V} -> U) forall U max_of, max_of?(&block : {K, V} -> U) forall U max_of?, min min, min? min?, min_by(&block : {K, V} -> U) forall U min_by, min_by?(&block : {K, V} -> U) forall U min_by?, min_of(&block : {K, V} -> U) forall U min_of, min_of?(&block : {K, V} -> U) forall U min_of?, minmax minmax, minmax? minmax?, minmax_by(&block : {K, V} -> U) forall U minmax_by, minmax_by?(&block : {K, V} -> U) forall U minmax_by?, minmax_of(&block : {K, V} -> U) forall U minmax_of, minmax_of?(&block : {K, V} -> U) forall U minmax_of?, none?(&block)
none? none?, one?(&block) one?, partition(&block) partition, product(&block)
product(initial : Number, &block)
product
product(initial : Number) product, reduce(&block)
reduce(memo, &block) reduce, reject(&block : {K, V} -> ) reject, select(&block : {K, V} -> ) select, size size, skip(count : Int) skip, skip_while(&block) skip_while, sum(initial)
sum
sum(initial, &block)
sum(&block) sum, take_while(&block) take_while, to_a to_a, to_h to_h, to_set to_set

### Instance methods inherited from class `Reference`

==(other : self)
==(other) ==, dup dup, hash hash, inspect(io : IO) : Nil inspect, object_id : UInt64 object_id, pretty_print(pp) : Nil pretty_print, same?(other : Reference)
same?(other : Nil) same?, to_s(io : IO) : Nil to_s

### Class methods inherited from class `Reference`

new new

### Instance methods inherited from class `Object`

!=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)
===(other : YAML::Any)
===(other) ===, =~(other) =~, class class, dup dup, hash hash, inspect(io : IO)
inspect inspect, itself itself, not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, tap(&block) tap, to_json(io : IO)
to_json to_json, to_pretty_json(indent : String = " ")
to_pretty_json(io : IO, indent : String = " ") to_pretty_json, to_s
to_s(io : IO) to_s, to_yaml(io : IO)
to_yaml to_yaml, try(&block) try

### Class methods inherited from class `Object`

from_json(string_or_io, root : String) : self
from_json(string_or_io) : self from_json, from_yaml(string_or_io) : self from_yaml

## Class Method Detail

def self.new(block : Hash(K, V), K -> V? = nil, initial_capacity = nil) #
def self.new(pull : YAML::PullParser, &block) #
def self.new(initial_capacity = nil, &block : Hash(K, V), K -> V) #
def self.new(default_value : V, initial_capacity = nil) #
def self.new(pull : JSON::PullParser) #
def self.new(pull : YAML::PullParser) #
def self.zip(ary1 : Array(K), ary2 : Array(V)) #

Zips two arrays into a `Hash`, taking keys from ary1 and values from ary2.

    Hash.zip(["key1", "key2", "key3"], ["value1", "value2", "value3"])
    # => {"key1" => "value1", "key2" => "value2", "key3" => "value3"}

## Instance Method Detail

def ==(other : Hash) #

Compares with other. Returns `true` if all key-value pairs are the same.

def [](key) #

See also: `Hash#fetch`.

def []=(key : K, value : V) #

Sets the value of key to the given value.

    h = {} of String => String
    h["foo"] = "bar"
    h["foo"] # => "bar"

def []?(key) #

Returns the value for the key given by key. If not found, returns `nil`. This ignores the default value set by `Hash.new`.

    h = {"foo" => "bar"}
    h["foo"]? # => "bar"
    h["bar"]? # => nil

    h = Hash(String, String).new("bar")
    h["foo"]? # => nil

def clear #

Empties a `Hash` and returns it.

    hash = {"foo" => "bar"}
    hash.clear # => {}

def clone #

Similar to `#dup`, but duplicates the values as well.

    hash_a = {"foobar" => {"foo" => "bar"}}
    hash_b = hash_a.clone
    hash_b["foobar"]["foo"] = "baz"
    hash_a # => {"foobar" => {"foo" => "bar"}}

def compact #

Returns new `Hash` without `nil` values.

    hash = {"hello" => "world", "foo" => nil}
    hash.compact # => {"hello" => "world"}

def compact! #

Removes all `nil` value from `self`. Returns `nil` if no changes were made.

    hash = {"hello" => "world", "foo" => nil}
    hash.compact! # => {"hello" => "world"}
    hash.compact! # => nil

def delete(key) #

Deletes the key-value pair and returns the value, otherwise returns `nil`.

    h = {"foo" => "bar"}
    h.delete("foo")     # => "bar"
    h.fetch("foo", nil) # => nil

def delete(key, &block) #

Deletes the key-value pair and returns the value, else yields key with given block.

    h = {"foo" => "bar"}
    h.delete("foo") { |key| "#{key} not found" } # => "bar"
    h.fetch("foo", nil)                          # => nil
    h.delete("baz") { |key| "#{key} not found" } # => "baz not found"

def delete_if(&block) #

Deletes each key-value pair for which the given block returns `true`.

    h = {"foo" => "bar", "fob" => "baz", "bar" => "qux"}
    h.delete_if { |key, value| key.starts_with?("fo") }
    h # => { "bar" => "qux" }

def dup #

Duplicates a `Hash`.

    hash_a = {"foo" => "bar"}
    hash_b = hash_a.dup
    hash_b.merge!({"baz" => "qux"})
    hash_a # => {"foo" => "bar"}

def each #

Returns an iterator over the hash entries. Which behaves like an `Iterator` returning a `Tuple` consisting of the key and value types.

    hsh = {"foo" => "bar", "baz" => "qux"}
    iterator = hsh.each

    iterator.next # => {"foo", "bar"}
    iterator.next # => {"baz", "qux"}

def each(&block) : Nil #

Calls the given block for each key-value pair and passes in the key and the value.

    h = {"foo" => "bar"}

    h.each do |key, value|
      key   # => "foo"
      value # => "bar"
    end

    h.each do |key_and_value|
      key_and_value # => {"foo", "bar"}
    end

def each_key #

Returns an iterator over the hash keys. Which behaves like an `Iterator` consisting of the key's types.

    hsh = {"foo" => "bar", "baz" => "qux"}
    iterator = hsh.each_key

    key = iterator.next
    key # => "foo"

    key = iterator.next
    key # => "baz"

def each_key(&block) #

Calls the given block for each key-value pair and passes in the key.

    h = {"foo" => "bar"}
    h.each_key do |key|
      key # => "foo"
    end

def each_value(&block) #

Calls the given block for each key-value pair and passes in the value.

    h = {"foo" => "bar"}
    h.each_value do |value|
      value # => "bar"
    end

def each_value #

Returns an iterator over the hash values. Which behaves like an `Iterator` consisting of the value's types.

    hsh = {"foo" => "bar", "baz" => "qux"}
    iterator = hsh.each_value

    value = iterator.next
    value # => "bar"

    value = iterator.next
    value # => "qux"

def empty? #

Returns `true` when hash contains no key-value pairs.

    h = Hash(String, String).new
    h.empty? # => true

    h = {"foo" => "bar"}
    h.empty? # => false

def fetch(key, &block) #

Returns the value for the key given by key, or when not found calls the given block with the key.

    h = {"foo" => "bar"}
    h.fetch("foo") { |key| key.upcase } # => "bar"
    h.fetch("bar") { |key| key.upcase } # => "BAR"

def fetch(key, default) #

Returns the value for the key given by key, or when not found the value given by default. This ignores the default value set by `Hash.new`.

    h = {"foo" => "bar"}
    h.fetch("foo", "foo") # => "bar"
    h.fetch("bar", "foo") # => "foo"

def fetch(key) #

Returns the value for the key given by key. If not found, returns the default value given by `Hash.new`, otherwise raises `KeyError`.

    h = {"foo" => "bar"}
    h["foo"] # => "bar"

    h = Hash(String, String).new("bar")
    h["foo"] # => "bar"

    h = Hash(String, String).new { "bar" }
    h["foo"] # => "bar"

    h = Hash(String, String).new
    h["foo"] # raises KeyError

def first_key #

Returns the first key in the hash.

def first_key? #

Returns the first key if it exists, or returns `nil`.

    hash = {"foo" => "bar"}
    hash.first_key? # => "foo"
    hash.clear
    hash.first_key? # => nil

def first_value #

Returns the first value in the hash.

def first_value? #

Similar to `#first_key?`, but returns its value.

def has_key?(key) #

Returns `true` when key given by key exists, otherwise `false`.

    h = {"foo" => "bar"}
    h.has_key?("foo") # => true
    h.has_key?("bar") # => false

def has_value?(val) #

Returns `true` when value given by value exists, otherwise `false`.

    h = {"foo" => "bar"}
    h.has_value?("foo") # => false
    h.has_value?("bar") # => true

def hash #

See also: `Object#hash`.

    foo = {"foo" => "bar"}
    foo.hash # => 3247054

def inspect(io : IO) #
def invert #

Inverts keys and values. If there are duplicated values, the last key becomes the new value.

    {"foo" => "bar"}.invert                 # => {"bar" => "foo"}
    {"foo" => "bar", "baz" => "bar"}.invert # => {"bar" => "baz"}

def key(value) #

Returns the first key with the given value, else raises `KeyError`.

    hash = {"foo" => "bar", "baz" => "qux"}
    hash.key("bar")    # => "foo"
    hash.key("qux")    # => "baz"
    hash.key("foobar") # raises KeyError (Missing hash key for value: foobar)

def key(value, &block) #

Returns the first key with the given value, else yields value with the given block.

    hash = {"foo" => "bar"}
    hash.key("bar") { |value| value.upcase } # => "foo"
    hash.key("qux") { |value| value.upcase } # => "QUX"

def key?(value) #

Returns the first key with the given value, else `nil`.

    hash = {"foo" => "bar", "baz" => "qux"}
    hash.key?("bar")    # => "foo"
    hash.key?("qux")    # => "baz"
    hash.key?("foobar") # => nil

def key_index(key) #

Returns the index of the given key, or `nil` when not found. The keys are ordered based on when they were inserted.

    h = {"foo" => "bar", "baz" => "qux"}
    h.key_index("foo") # => 0
    h.key_index("qux") # => nil

def keys #

Returns a new `Array` with all the keys.

    h = {"foo" => "bar", "baz" => "bar"}
    h.keys # => ["foo", "baz"]

def merge(other : Hash(L, W)) forall L, W #

Returns a new `Hash` with the keys and values of this hash and other combined. A value in other takes precedence over the one in this hash.

    hash = {"foo" => "bar"}
    hash.merge({"baz" => "qux"})
    # => {"foo" => "bar", "baz" => "qux"}
    hash
    # => {"foo" => "bar"}

def merge(other : Hash(L, W), &block : K, V, W -> V | W) forall L, W #
def merge!(other : Hash) #

Similar to `#merge`, but the receiver is modified.

    hash = {"foo" => "bar"}
    hash.merge!({"baz" => "qux"})
    hash # => {"foo" => "bar", "baz" => "qux"}

def merge!(other : Hash, &block) #
def pretty_print(pp) : Nil #
def rehash #
def reject(*keys) #

Returns a new `Hash` without the given keys.

    {"a" => 1, "b" => 2, "c" => 3, "d" => 4}.reject("a", "c") # => {"b" => 2, "d" => 4}

def reject(&block : K, V -> _) #

Returns a new hash consisting of entries for which the block returns `false`.

    h = {"a" => 100, "b" => 200, "c" => 300}
    h.reject { |k, v| k > "a" } # => {"a" => 100}
    h.reject { |k, v| v < 200 } # => {"b" => 200, "c" => 300}

def reject!(&block : K, V -> _) #

Equivalent to `Hash#reject`, but makes modification on the current object rather that returning a new one. Returns `nil` if no changes were made.

def reject!(keys : Array | Tuple) #

Removes a list of keys out of hash.

    h = {"a" => 1, "b" => 2, "c" => 3, "d" => 4}.reject!("a", "c")
    h # => {"b" => 2, "d" => 4}

def reject!(*keys) #
def select(&block : K, V -> _) #

Returns a new hash consisting of entries for which the block returns `true`.

    h = {"a" => 100, "b" => 200, "c" => 300}
    h.select { |k, v| k > "a" } # => {"b" => 200, "c" => 300}
    h.select { |k, v| v < 200 } # => {"a" => 100}

def select(keys : Array | Tuple) #

Returns a new `Hash` with the given keys.

    {"a" => 1, "b" => 2, "c" => 3, "d" => 4}.select("a", "c") # => {"a" => 1, "c" => 3}

def select(*keys) #
def select!(&block : K, V -> _) #

Equivalent to `Hash#select` but makes modification on the current object rather that returning a new one. Returns `nil` if no changes were made

def select!(keys : Array | Tuple) #

Removes every element except the given ones.

    h = {"a" => 1, "b" => 2, "c" => 3, "d" => 4}.select!("a", "c")
    h # => {"a" => 1, "c" => 3}

def select!(*keys) #
def shift(&block) #

Deletes and returns the first key-value pair in the hash. Yields to the given block if the hash is empty.

    hash = {"foo" => "bar", "baz" => "qux"}
    hash.shift { true } # => {"foo", "bar"}
    hash                # => {"baz" => "qux"}

    hash = {} of String => String
    hash.shift { true } # => true
    hash                # => {}

def shift #

Deletes and returns the first key-value pair in the hash, or raises `IndexError` if the hash is empty.

    hash = {"foo" => "bar", "baz" => "qux"}
    hash.shift # => {"foo", "bar"}
    hash       # => {"baz" => "qux"}

    hash = {} of String => String
    hash.shift # raises IndexError

def shift? #

Same as `#shift`, but returns `nil` if the hash is empty.

    hash = {"foo" => "bar", "baz" => "qux"}
    hash.shift? # => {"foo", "bar"}
    hash        # => {"baz" => "qux"}

    hash = {} of String => String
    hash.shift? # => nil

def size : Int32 #
def to_h #

Returns `self`.

def to_json(json : JSON::Builder) #
def to_s(io : IO) #

Converts to a `String`.

    h = {"foo" => "bar"}
    h.to_s       # => "{\"foo\" => \"bar\"}"
    h.to_s.class # => String

def to_yaml(yaml : YAML::Builder) #
def values #

Returns only the values as an `Array`.

    h = {"foo" => "bar", "baz" => "qux"}
    h.values # => ["bar", "qux"]

def values_at(*indexes : K) #

Returns a tuple populated with the elements at the given indexes. Raises if any index is invalid.

    {"a" => 1, "b" => 2, "c" => 3, "d" => 4}.values_at("a", "c") # => {1, 3}