[...]
> A lot of Ruby's clarity comes not from being able to write things
> clearly in the "raw" language, but from being able to easily
> customize the language for your needs.Of course, and that is what I am asking in the whole thread! Is there
a nicer way for this loop... Let's see. I have this each_with_next
now, but still I am completely unstatisfied with my loop. But I am now
convinced that I have the optimal solution, even if it the way it
looks now. And btw., I need a look-ahead for this specific purpose.
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