Just for fun, if the Array extension is your choice, can you go for something more flexible, like implementing the same? method same? :
class Array def same? &block if block_given? f = block.call(first) all? {|a| block.call(a) == f} else all? {|a| a == first } end end end
This allows:
[[1,2], [5,6], [8,9]].same?(&:size)
or
[[1,2], [7,8], [5,6], [8,9]].same?(&:max)
or just (by default it will be compared with == )
[[1,2], [7,8], [5,6], [8,9]].same?
source share