Skip to content

Instantly share code, notes, and snippets.

@otaznik-net
Created September 5, 2019 12:25
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 otaznik-net/f7a2f23429e0376adefaa713cce398b8 to your computer and use it in GitHub Desktop.
Save otaznik-net/f7a2f23429e0376adefaa713cce398b8 to your computer and use it in GitHub Desktop.
2.6.3 :001 > A = %w[a b c d e f]
=> ["a", "b", "c", "d", "e", "f"]
2.6.3 :002 > B = %w[1 2 3 4 5]
=> ["1", "2", "3", "4", "5"]
2.6.3 :003 > x = A.each_slice(2)
=> #<Enumerator: ["a", "b", "c", "d", "e", "f"]:each_slice(2)>
2.6.3 :004 > B.map { |i| [i, begin; x.next; rescue; end].compact}.flatten
=> ["1", "a", "b", "2", "c", "d", "3", "e", "f", "4", "5"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment