title: How to get the next element in an array but get first if current is last
body: <p>I have an array of color codes:</p>
  
  <pre><code>array = %w(#646C74 #F68848 #1FA45C etc...)
  </code></pre>
  
  <p>Every time I query the array I compare with what color was lastly used and want to get the next one. If the last one used is the last in the array, I want the first one. </p>
  
  <p>Is there a more dedicated or succinct way to solve this than:</p>
  
  <pre><code>index_of_last_used_color = array.index(last_used_color)
  next_position = index_of_last_used_color + 1
  if color = array[next_position]
      return color
  else
      return array.first
  end
  </code></pre>