method

fetch_values

Importance_1
Ruby on Rails latest stable (v7.1.3.2) - 0 notes - Class: ActiveSupport::HashWithIndifferentAccess
fetch_values(*indices, &block) public

Returns an array of the values at the specified indices, but also raises an exception when one of the keys can’t be found.

hash = ActiveSupport::HashWithIndifferentAccess.new
hash[:a] = 'x'
hash[:b] = 'y'
hash.fetch_values('a', 'b') # => ["x", "y"]
hash.fetch_values('a', 'c') { |key| 'z' } # => ["x", "z"]
hash.fetch_values('a', 'c') # => KeyError: key not found: "c"
Show source
Register or log in to add new notes.