I came across this beauty in some old code of mine:

1
2
3
4
5
6
7
def same_modality? list
  check = list[0][0]
  list.each do |i|
    return false if check != i[0]
  end
  return true
end

This was "necessary" because I got an array of one-element arrays back, and I wanted to check whether or not that one element was the same across the array.

Three seconds of thinking made me realize that just maybe, I could do this:

1
list.uniq.size == 1

I like Ruby.