Skip to content

Instantly share code, notes, and snippets.

@bxt
Created October 6, 2017 13:26
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 bxt/5c1d9e52e178541a015381d65b449466 to your computer and use it in GitHub Desktop.
Save bxt/5c1d9e52e178541a015381d65b449466 to your computer and use it in GitHub Desktop.
Map over ruby arrays / enumerables and have the last element marked with a boolean
def with_last(enumerable, length = enumerable.length)
Enumerator.new do |yielder|
enumerable.each_with_index do |element, index|
yielder.yield(element, index == length - 1)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment