From: Steve Litt Date: 2005-12-08T21:41:39+09:00 Subject: Re: increasing counter whithin loop? On Thursday 08 December 2005 05:47 am, Kroeger, Simon (ext) wrote: > > > able to use it. I'd probably have to create each_with_prev_and_next. > > It's allready there: > > ----------------------------------------------------------------- > require 'enumerator' > a=[:a, :b, :b, :c, :b, :d, :e, :e] > > ([nil] + a + [nil]).each_cons(3) do |prv, this, nxt| > next if prv == this > print 'double_' if this == nxt > puts this > end > ----------------------------------------------------------------- > output: > a > double_b > c > b > d > double_e > > cheers > > Simon Hi Simon, I just ran your code, and got the exact output you got, but I don't understand a bit of it. First, I'm unclear as to the use of variables starting with colon. What are they, when are they used? Also, are prv, this and nxt just any old variables, or are they somehow supplied by enumerator? Is variable a a string, an array, or something else? Why did you place an array containing only nil before and after a in the parentheses? Thank you for this code. When I asked my question about how to stop writing Ruby with a Perl accent, I was hoping to understand constructs like this one. I have about 8 days experience with Ruby and so have some catching up to do. Thanks SteveT Steve Litt http://www.troubleshooters.com slitt@troubleshooters.com