How do I check an array for duplicates?<>
This question already has an answer here:
Just call uniq on it (which returns a new array without duplicates) and see whether the uniqed array has less elements than the original:
if a.uniq.length == a.length puts "a does not contain duplicates" else puts "a does contain duplicates" end
Note that the objects in the array need to respond to hash and eql? in a meaningful for uniq to work properly.