重複した項目を検出する
a = ["A", "B", "C", "B", "A"] a.detect{ |e| a.count(e) > 1 } # => ['A', 'B']
Ruby: How to find and return a duplicate value in array? - stackoverflow