From: Erwin Abbott Date: 2007-06-11T02:05:56+09:00 Subject: Re: Overloading Array Subtraction operator On 6/10/07, Erwin Abbott wrote: > Yes, I responded hastily. The rdocs for Array#- don't say how objects > are compared so I made a bad assumption. I only meant to convey it > wasn't being done by comparing values. ... at least with the array of Hashes, Hash#hash is used and not Hash#== or some value based comparison. I'm not sure how it's done with Strings or Fixnums, I'd have to check the source code probably. Check it out with the profiler: $ ruby -rprofile -e '[{:a=>3}] - [{:b=>0,:a=>0}]' % cumulative self self total time seconds seconds calls ms/call ms/call name 0.00 0.00 0.00 2 0.00 0.00 Kernel.hash 0.00 0.00 0.00 1 0.00 0.00 Array#- 0.00 0.01 0.00 1 0.00 10.00 #toplevel $ ruby -rprofile -e '%w[a b c] - %w[b d e f]' % cumulative self self total time seconds seconds calls ms/call ms/call name 0.00 0.00 0.00 1 0.00 0.00 Array#- 0.00 0.01 0.00 1 0.00 10.00 #toplevel $ ruby -rprofile -e '[1,2,3] - [0,3,5]' % cumulative self self total time seconds seconds calls ms/call ms/call name 0.00 0.00 0.00 1 0.00 0.00 Array#- 0.00 0.01 0.00 1 0.00 10.00 #toplevel Regards, Erwin