From: Nicko Date: 2007-06-10T17:30:14+09:00 Subject: Re: Overloading Array Subtraction operator Wow! Thank you both! I ended up with class SuperArray < Array def -(other) self.select{|x| !other.include? x} end end and it works great :) I can optimise it later :) Nicko On Jun 10, 5:56 pm, "Erwin Abbott" wrote: > The - operator compares objects by their ID, so they aren't removed > unless they are instances of the same object. They may have the same > value, but be separate instances like this example. You can accomplish > what you want like this: > > array1.select{|x| !array2.include? x} > # => [{:name=>"stan", :phone=>"hehe}] > > Array#include? compares using == so they are compared by value, not by > their #object_id. > > [:a, :b, :c].object_id # => 2711200 > [:a, :b, :c].object_id # => 2690960 ... a new instance, same value > > Regards, > Erwin