From: William James Date: 2007-01-23T07:45:08+09:00 Subject: Re: array equality question 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? The reason for this behavior is that the creator of Ruby and most of its users aren't devoid of knowledge of programming. An array is not a set. An array is not a hash (a.k.a. associative array). So of course order matters. Does the order in which you read the chapters of a novel matter? If order doesn't matter, then why is there a 'sort' method that changes the order of an array?