ruby - Iterate over loop accessing two elements if they exist -


well, haven't found clean solution write code in ruby:

# java style version: array.each |i, el|   if < array.length - 1      process(array[i], array[i+1])   end end  # nice if this: array.each |i, el, next|   process(el, next) end 

you can use each_cons:

array.each_cons(2) |a, b|   process(a, b) end 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -