Re: Array#uniq vs Array#-
Cristian Rivera <[email protected]>
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <[email protected]> |
It comes down to a matter of uniqueness. In the first part of your example `uniq` returns an Array with both elements because it uses the object hash AND `eql?` to determine uniqueness. In the last part of your example the `-` minus in Ruby removes all unique objects from the Arrays before actually performing the subtraction therefore giving you an empty Array. It removes the unique values between the two because you obviously can’t subtract two things that aren’t equal. Even though you are setting `eql?` in your class the object hash between the two still varies. Thanks, Cristian Rivera > On Apr 16, 2019, 5:30 PM -0400, Clavius Tales <[email protected]>, wrote: > Hi. > > https://repl.it/repls/FantasticIrritatingObjectcode > > Do you know why? > > Thanks. > > Unsubscribe: <mailto:[email protected]?subject=unsubscribe> > <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk> Unsubscribe: <mailto:[email protected]?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>