Issue #10017 has been updated by Matthew Kerwin.


-1 for values_at! (this isn't a "!" method)

+0 for fetch_at (it's not clear that it isn't just an alias for #fetch)

+1 for fetch_values

----------------------------------------
Feature #10017: Add `Hash#values_at!`
https://bugs.ruby-lang.org/issues/10017#change-49009

* Author: Wojtek Mach
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
----------------------------------------
I'm proposing to add a new method `Hash#values_at!` that's basically a combination of `#values_at` and `#fetch`.

When dealing with configuration I prefer to use `#fetch` to fail early and this would be useful to read multiple keys at a time.
An example (not strictly on a Hash, but you get the idea) could be:

```ruby
repo, token = ENV.values_at!('GITHUB_REPO', 'GITHUB_TOKEN')

ENV.values_at!('INVALID') # raises KeyError

# not sure if that useful, but I provide it here for the sake of completeness
ENV.values_at!("SHELL", "INVALID") { |k| k + " is missing" } # => ["/bin/bash", "INVALID is missing"]
```

Another name for this could be `#fetch_at`, perhaps.

P.S. I'm attaching a patch that was done using mostly trial and error

---Files--------------------------------
values_at_bang.patch (1.53 KB)
fetch_at.patch (2.18 KB)


-- 
https://bugs.ruby-lang.org/