a = [1, 2, 56, 3, 56, 7, 7, 7, 56, 40, 40, 40]
a.group_by do |e|
e
end.values.max_by(&:size).first
This return 56
but how we do to return all the common values like: [56,7,40]
We can create a hash with all repetitions and after with select get the numbers with the max repetitions value. But maybe there are a easier way to do this.