Friday, May 6, 2011

Compare two arrays in Ruby

Today I had a need to compare 2 arrays in Ruby and if they are the same, then do something else something. I googled and found this solution

Let us say a1 and a2 are the arrays then

diff=a1-a2
if diff.empty ? then
puts "arrays are the same"
else
puts "arrays are different"
end

No comments: