Is doc for Hash#each and Hash#each_pair wrong?

I was just assimilating some Ruby docs, and I noticed the Ruby docs page at http://ruby-doc.org . I happened to browse down to http://ruby-doc.org/core-2.3.0/Hash.html#method-i-each_pair and it seems to me that the doc for "each" and "each_pair" might be wrong, if some other internet references are correct (like https://www.ruby-forum.com/topic/163062).

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.

Hi
I think each and each_pair are the same, both depending on the count of
args inside |…|

Berg

···

Am 16.04.2016 00:56 schrieb "David M. Karr" <davidmichaelkarr@gmail.com>:

I was just assimilating some Ruby docs, and I noticed the Ruby docs page
at http://ruby-doc.org . I happened to browse down to
Class: Hash (Ruby 2.3.0) and it seems
to me that the doc for "each" and "each_pair" might be wrong, if some other
internet references are correct (like
https://www.ruby-forum.com/topic/163062\).

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.

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

The bug tracker is here:

Greetings
Marvin

···

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.

--
Blog: http://www.guelkerdev.de
PGP/GPG ID: F1D8799FBCC8BC4F

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:

[...]
    rb_define_method(rb_cHash,"each_pair", rb_hash_each_pair, 0);
    rb_define_method(rb_cHash,"each", rb_hash_each_pair, 0);
[...]

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/>