title: Return index of all occurrences of a character in a string in ruby
body: <p>I am trying to return the index's to all occurrences of a specific character in a string using Ruby. A example string is <code>"a#asg#sdfg#d##"</code> and the expected return is <code>[1,5,10,12,13]</code> when searching for <code>#</code> characters. The following code does the job but there must be a simpler way of doing this?</p>
  
  <pre><code>def occurances (line)
  
    index = 0
    all_index = []
  
    line.each_byte do |x|
      if x == '#'[0] then
        all_index &lt;&lt; index
      end
      index += 1
    end
  
    all_index
  end
  </code></pre>