Skip to content

Instantly share code, notes, and snippets.

@rbsgn
Created November 6, 2013 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbsgn/7331483 to your computer and use it in GitHub Desktop.
Save rbsgn/7331483 to your computer and use it in GitHub Desktop.
Last night I discovered Array#each_cons. Now I love Ruby even more!
2.0.0-p247 :008 > Array(1..5).each_cons(2) { |first, second| puts "#{first}, #{second}" }
1, 2
2, 3
3, 4
4, 5
=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment