"Simon Strandgaard" <0bz63fz3m1qt3001 / sneakemail.com> schrieb im
Newsbeitrag news:pan.2003.06.27.05.49.55.670426 / sneakemail.com...
> On Fri, 27 Jun 2003 10:48:56 +0900, Krishna Dole wrote:
>
> > Hi,
> > I'm having trouble using the & (intersection) method on two arrays of
> > objects. I know that if the objects don't have comparison methods, &
won't
> > work because it is looking at the object IDs rather than values stored
in
> > the objects, but I can't seem to get & to use the comparison methods I
want.
> >
> [snip code]
> > p (foo & bar) # returns an empty array! NOOOOO!!!!!
>
> There is no intersection(&) method.

There is:

07:31:22 [temp]: ri 'Array#&'
---------------------------------------------------------------- Array#&
     arr & anOtherArray -> anArray
------------------------------------------------------------------------
     Set Intersection---Returns a new array containing elements common
     to the two arrays, with no duplicates.
        [ 1, 1, 3, 5 ] & [ 1, 2, 3 ]   #=> [1, 3]

07:31:25 [temp]:

> Have you looked at 'set.rb' which is distributed with ruby ?

This should work with Arrays, too.  I've played around with class Trivial,
even overloaded eql?(), ==(), equal?(), id(), __id__() and object_id() to
to no avail.  The array from the union remains empty.  IMHO this is a bug
(my version is 1.7.3).

Regards

    robert