Method: Immutable::Hash#fetch_values

Defined in:
lib/immutable/hash.rb

#fetch_values(*wanted) ⇒ Vector

Return a Vector of the values which correspond to the wanted keys. If any of the wanted keys are not present in this Hash, raise KeyError exception.

Examples:

h = Immutable::Hash["A" => 1, "B" => 2, "C" => 3]
h.fetch_values("C", "A")  # => Immutable::Vector[3, 1]
h.fetch_values("C", "Z")  # => KeyError: key not found: "Z"

Parameters:

  • wanted (Array)

    The keys to retrieve

Returns:



604
605
606
607
# File 'lib/immutable/hash.rb', line 604

def fetch_values(*wanted)
  array = wanted.map { |key| fetch(key) }
  Vector.new(array.freeze)
end