Project

General

Profile

Actions

Bug #6872

closed

Array does not specify how it determines uniqueness of values

Added by agrimm (Andrew Grimm) over 11 years ago. Updated over 11 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
Backport:
[ruby-core:47199]

Description

=begin
The documentation of (({Array#uniq})) , and similar methods, does not specify how values are determined to be unique when a block is not given.

The Stack Overflow answer http://stackoverflow.com/a/8779948/38765 explains that (({Array#uniq})) works on the basis of looking at the hash method of each value in the array. However, this is not explained in the documentation of (({Array#uniq})) , or in (({Object#hash})) .

I think, but I'm not 100% sure, that there are other methods in Array that also use the hash method, such as (({Array#-})) . Ideally, all of these methods should be documented as using the hash method.
=end

Actions #1

Updated by drbrain (Eric Hodel) over 11 years ago

  • Assignee set to drbrain (Eric Hodel)

Updated by drbrain (Eric Hodel) over 11 years ago

These methods all use "Hash key equality", so #hash and #eql? control the behavior.

Updated by robin850 (Robin Dupret) over 11 years ago

Hello,

I allow myself to make a patch containing documentation : https://github.com/robin850/ruby/compare/enhance_documentation

I have just a question : I was looking in the code in order to see if some methods use Object#hash when comparing elements and I found the rb_ary_eql method. Why this one doesn't end with the _p suffix ? Is there any reason please ?

Have a nice day.

Updated by drbrain (Eric Hodel) over 11 years ago

Thank you, this patch looks good.

I imagine it's rb_ary_eql instead of rb_ary_eql_p due to history.

Updated by robin850 (Robin Dupret) over 11 years ago

drbrain (Eric Hodel) wrote:

Thank you, this patch looks good.

I imagine it's rb_ary_eql instead of rb_ary_eql_p due to history.

I'm sorry but how are you going to merge this ? Do you want me to open a pull request on github ?

Updated by drbrain (Eric Hodel) over 11 years ago

On Aug 16, 2012, at 12:40 AM, "robin850 (Robin Dupret)" wrote:

I'm sorry but how are you going to merge this ? Do you want me to open a pull request on github ?

If you add .patch or .diff to the github URL you get a diff.

If you'd like to create a pull request that's fine, but I'll do the exact same thing to the pull request URL to apply it.

Updated by robin850 (Robin Dupret) over 11 years ago

drbrain (Eric Hodel) wrote:

On Aug 16, 2012, at 12:40 AM, "robin850 (Robin Dupret)" wrote:

I'm sorry but how are you going to merge this ? Do you want me to open a pull request on github ?

If you add .patch or .diff to the github URL you get a diff.

If you'd like to create a pull request that's fine, but I'll do the exact same thing to the pull request URL to apply it.

Okay, I think open a pull request it's a waste of time ; You can make the change with the URL and the .diff. Sorry for this disturbing, I'm not familiar with contributing. Have a nice day. :)

Actions #8

Updated by zzak (zzak _) over 11 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r36965.
Andrew, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • array.c (rb_ary_diff, rb_ary_uniq):
    Enhance documentation for array uniqueness
    Based on a patch by Robin Dupret
    [Bug #6872] [ruby-core:47209]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0