Skip to content

Instantly share code, notes, and snippets.

@wycats
Created October 7, 2011 06:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wycats/1269629 to your computer and use it in GitHub Desktop.
Save wycats/1269629 to your computer and use it in GitHub Desktop.
# Obviously this could be done with .join("\n"), but let's say we didn't have join...
x = [1,2,3,4]
# This will yield: 1,2 then 2,3 then 3,4 then 4,nil
(x + [nil]).each_cons(2) do |item, next_item|
puts item
puts "\n" if next_item
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment