On Fri, 17 Aug 2007 20:26:33 +0200, Matteo Gottardi wrote:

> Hi all. Why this don't work??
> 
> # Begin code
> class Prova
>     attr_accessor :n
>     def initialize(n)
>         @n = n
>     end
>     def to_s
>         "#{@n}"
>     end
>     def ==(other)
>         @n == other.n
>     end
> end
> 
> p1 = [Prova.new(1), Prova.new(2)]
> p2 = [Prova.new(2)]
> puts (p1 - p2)
> # End code
> 
> Why the difference doesn't work like [1, 2] - [2] ?

A hash is used internally, and hash keys are compared for equality using 
#eql?. You also need to override #hash.

--Ken

-- 
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/