Nicko
6/10/2007 8:26:00 AM
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" <erwin.abb...@gmail.com> 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