title: Find indices of elements that match a given condition
body: <p>Given an array, how can I find all indices of elements those match a given condition?</p>
  
  <p>For example, if I have:</p>
  
  <pre><code>arr = ['x', 'o', 'x', '.', '.', 'o', 'x']
  </code></pre>
  
  <p>To find all indices where the item is <code>x</code>, I could do:</p>
  
  <pre><code>arr.each_with_index.map { |a, i| a == 'x' ? i : nil }.compact   # =&gt; [0, 2, 6]
  </code></pre>
  
  <p>or</p>
  
  <pre><code>(0..arr.size-1).select { |i| arr[i] == 'x' }   # =&gt; [0, 2, 6]
  </code></pre>
  
  <p>Is there a nicer way to achieve this?</p>