Re: increasing counter whithin loop?


#1

The each_with_previous was a very nice hint, thanks, even if I wasn’t
able to use it. I’d probably have to create each_with_prev_and_next.

Hmm, I still don’t know exactly what you realy want/need. If you just
want to replace two instances of :b with double_b, have a look at this:


require ‘enumerator’
a=[:a, :b, :b, :c, :b, :d, :e]

a[a.to_enum(:each_cons, 2).to_a.index([:b, :b]), 2] = ‘double_b’
puts a

(yes, of course this is completely without error checking and
doesn’t work for more than one occurrence of :b, :b)

As I said, I’m not realy sure that’s what you are looking for…

cheers

Simon