Ok, this has been discussed at length previously,
and it appears that the implementation has
changed.
Consider:
in 1.6.7
[1,1,2,2,3,3] - [3] => [1,2]
in 1.8.0
[1,1,2,2,3,3] - [3] => [1,1,2,2]
I think this last algorithm was chosen for
performance reasons. The problem is, the #- operation
is neither explainable by the Array being considered a bag
or a set. Plus, since this operation seems to change
with revisions, it is hard to rely upon.
The one explanation that is consistent between the two
is if #uniq is applied to both sides of the equation.
Tbat is,
([1,1,2,2,3,3].uniq - [3].uniq).uniq #=> [1,2].uniq => [1,2]
([1,1,2,2,3,3].uniq - [3].uniq).uniq #=> [1,1,2,2].uniq => [1,2]
So it would seem that Array#- is incomplete and the user
is required to apply #uniq to the result.
All I can say is, Why?
···
–
Jim Freeze
Mandrell: "You know what I think?"
Doctor: “Ah, ah that’s a catch question. With a brain your size you
don’t think, right?”
– Dr. Who