I\'m using Ruby 1.8.6 with Rails 1.2.3, and need to determine whether two arrays have the same elements, regardless of whether or not they\'re in the same order. One of the
If you expect [:a, :b] != [:a, :a, :b] to_set doesn't work. You can use frequency instead:
[:a, :b] != [:a, :a, :b]
to_set
class Array def frequency p = Hash.new(0) each{ |v| p[v] += 1 } p end end [:a, :b].frequency == [:a, :a, :b].frequency #=> false [:a, :b].frequency == [:b, :a].frequency #=> true