Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Hash#fetch_values #776

Closed
wants to merge 1 commit into from
Closed

Add Hash#fetch_values #776

wants to merge 1 commit into from

Conversation

wojtekmach
Copy link

* hsh.fetch_values(key, ...) { |key| block } -> array
*
* Return an array containing the values associated with the given keys
* but also raises an <code>KeyError</code> when one of keys can't be found.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo I think, "raises an KeyError" => "raises a KeyError"

@timoschilling
Copy link
Contributor

I would be great to have a fetch_values and a fetch_values!, fetch_values shouldn't raise a error and fetch_values! should do it.

@wojtekmach
Copy link
Author

@timoschilling

Shouldn't this be h.fetch_values("cow", "bird") { |k| k.upcase } #=> ["BOVINE", "BIRD"]

no, we want to only invoke the block when the key is not present. "cow" key is present in the hash, "bird" isn't.

I would be great to have a fetch_values and a fetch_values!, fetch_values shouldn't raise a error and fetch_values! should do it.

there's already Hash#values_at that doesn't raise an error, and here fetch_values is supposed to be a companion method. See https://bugs.ruby-lang.org/issues/10017 for more information.

@wojtekmach
Copy link
Author

@nobu any comments about this? seems there was good initial feedback about this proposal: https://bugs.ruby-lang.org/issues/10017. Please let me know what can I do to push this forward

@nobu nobu closed this in 86eaa24 Jun 12, 2015
nurse pushed a commit to nurse/ruby that referenced this pull request Sep 18, 2015
* hash.c (rb_hash_fetch_values): add `Hash#fetch_values`.
  [Feature ruby#10017] [Fix rubyGH-776]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
@wojtekmach wojtekmach deleted the fetch_values branch March 2, 2016 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants