Re: Array#uniq vs Array#-

Gerald Bauer <[email protected]>
Newsgroups gmane.comp.lang.ruby.general
Message-ID <CAAxEZd_oF9vAY6KydsvqwBMxEyo-daXUKEkfWwWSCT-=oP_Hyg@mail.gmail.com>
Hello,

   Just looked at the 1st result in the "ruby uniq" Google search,
that is, the official Array RDoc [1].

    If you look at Array#uniq it tells you:

> It compares values using their hash and eql? methods for efficiency.

   If you try it. Add to your Any class:

   def hash() 1; end

   And retry:

  [Any.new,Any.new].uniq
  => [#<Any:0x111>]

    Now it works as you expect.  Cheers. Prost.

[1] https://ruby-doc.org/core-2.5.0/Array.html#method-i-uniq

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.