Method: ActiveSupport::HashWithIndifferentAccess#fetch_values
- Defined in:
- activesupport/lib/active_support/hash_with_indifferent_access.rb
#fetch_values(*indices, &block) ⇒ Object
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"
229 230 231 |
# File 'activesupport/lib/active_support/hash_with_indifferent_access.rb', line 229 def fetch_values(*indices, &block) indices.collect { |key| fetch(key, &block) } end |