From the other references, it appears that "each" sends the block an array of two elements containing the key and the value, whereas "each_pair" sends the block two parameters, being the key and value.
This doc page, however, seems ambiguous in multiple ways when describing these two methods. The text description for both seems to be identical, but then both examples below "each" and "each_pair" seem to only show an "each" example, but where the block takes two parameters, seemingly being "each_pair" instead of "each". I'm confused.
I would have filed a bug on the issue tracker, but the links to that seem self-referential. I can't actually get to the interface for submitting a bug.
From the other references, it appears that "each" sends the block an array
of two elements containing the key and the value, whereas "each_pair" sends
the block two parameters, being the key and value.
This doc page, however, seems ambiguous in multiple ways when describing
these two methods. The text description for both seems to be identical,
but then both examples below "each" and "each_pair" seem to only show an
"each" example, but where the block takes two parameters, seemingly being
"each_pair" instead of "each". I'm confused.
I would have filed a bug on the issue tracker, but the links to that seem
self-referential. I can't actually get to the interface for submitting a
bug.
Am Fri, 15 Apr 2016 15:56:29 -0700 schrieb "David M. Karr" <davidmichaelkarr@gmail.com>:
I would have filed a bug on the issue tracker, but the links to that
seem self-referential. I can't actually get to the interface for
submitting a bug.
Note that the documentation of Hash#each ( http://ruby-doc.org/core-2.3.0/Hash.html#method-i-each) mentions #each
_and_ #each_pair. If you click "click to toggle source" you can see that
the corresponding C function is rb_hash_each_pair. If you grep the source
for calls to this function you'll find two in Init_Hash:
So #each_pair and #each are one and the same method.
Best regards
···
--
Greg Navis
I help small software companies to scale Heroku-hosted Rails apps.
Free, biweekly scalability newsletter for SaaS CEOs
<http://www.gregnavis.com/newsletter/>