I need to check whether two arrays contain the same data in any order. Using the imaginary compare method, I would like to do:
compare
arr1 = [1,2,3,5,4
You can open array class and define a method like this.
array
class Array def compare(comparate) to_set == comparate.to_set end end arr1.compare(arr2) irb => true
OR use simply
arr1.to_set == arr2.to_set irb => true