I try to clean my Code. The first Version uses each_with_index. In the second version I tried to compact the code with the Enumerable.inject_with_index-constr
each_with_index
Enumerable.inject_with_index-constr
lines = %w(a b c) indexes = lines.each_with_index.inject([]) do |acc, (el, ind)| acc << ind - 1 if el == "b" acc end indexes # => [0]