Skip to content

Conversation

ColinTheRobot
Copy link
Contributor

Problem

Colleague asked what the splat did in this example and I don't think it does anything but maybe tries to handle an edge case that doesn't exist in the provided for example.

What changed

  • assign h to the hash used in the example similar to earlier examples
  • remove unnecessary splat in front of element

- assign h to the hash used in the example similar to earlier examples
- remove unncessary splat in front of element
@ColinTheRobot ColinTheRobot changed the title Clarify example for #each_with_object Clarify example for Enumerable#each_with_object Apr 19, 2022
@ColinTheRobot ColinTheRobot changed the title Clarify example for Enumerable#each_with_object [Documentation] Clarify example for Enumerable#each_with_object Apr 19, 2022
@ColinTheRobot ColinTheRobot changed the title [Documentation] Clarify example for Enumerable#each_with_object [DOC] Clarify example for Enumerable#each_with_object Apr 19, 2022
@Maumagnaguagno
Copy link
Contributor

Maumagnaguagno commented Apr 19, 2022

You could even skip element: h.each_with_object({}) {|(k, v), h| h[v] = k }.
Perhaps it is a better idea to not assign before the example, otherwise there are two hvariables (one outside and one inside block, each pointing to a different hash):
{foo: 0, bar: 1, baz: 2}.each_with_object({}) {|(k, v), h| h[v] = k }

@ColinTheRobot
Copy link
Contributor Author

You could even skip element: h.each_with_object({}) {|(k, v), h| h[v] = k }. Perhaps it is a better idea to not assign before the example, otherwise there are two hvariables (one outside and one inside block, each pointing to a different hash): {foo: 0, bar: 1, baz: 2}.each_with_object({}) {|(k, v), h| h[v] = k }

That's a good shout 🤔 A lot of stuff happening in this method. Will have another go with this feedback in mind

@jeremyevans jeremyevans merged commit 9e8841e into ruby:master Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants