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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -