title: Ruby: check if all array elements are equal
body: <p>I'm having a bit of a 'problem' with Ruby code.
  I want to check if all elements of an array are equal.</p>
  
  <p>For example, say I have an array of only 5s:</p>
  
  <pre><code>arr = [5, 5, 5, 5, 5]
  </code></pre>
  
  <p>I know I can do something like</p>
  
  <pre><code>arr[0] == arr[1] == arr[2] == arr[3] # == arr[4] == ...
  </code></pre>
  
  <p>but this is impossible for huge arrays and also not very Ruby-like in my opinion.
  We can improve it by doing something like this:</p>
  
  <pre><code>def all_equal?(arr)
    for i in 0..(arr.size-2)
      if arr[i] != arr[i+1] then
        return false
      end
    end
    true
  end
  </code></pre>
  
  <p>But I also think this is pretty ugly. So is there any built-in/better/shorter (more Ruby-esque) way to do this?</p>
  
  <p><strong>TL;DR what is the shortest/most Ruby-esque way to check if an array contains only one distinct element (e.g.</strong> <code>[5, 5, 5]</code>)<strong>?</strong></p>
  
  <p>Thanks.</p>