Robert Klemme
1/22/2007 10:38:00 PM
On 22.01.2007 23:27, Chris McMahon wrote:
> This took me by surprise:
>
> irb(main):001:0> a1 = ['x','y','z']
> => ["x", "y", "z"]
> irb(main):002:0> a2 = ['y','z','x']
> => ["y", "z", "x"]
>
> irb(main):008:0> puts "yo" if a1 == a2
> => nil
> irb(main):009:0> puts "yo" if a1 != a2
> yo
> => nil
>
> I assumed order of elements would not be considered for equality. Is
> there any particular reason for this behavior?
Why should order not matter? An array is an *ordered* list of elements
as indexing by position indicates. a1[0] == a2[0] will return false,
why then should a1 == a2 return true?
If you to ignore order you either have to compare sorted copies or
resort to Set.
Kind regards
robert