module Enumerable

open core class

Public Instance Methods

each_with_last() { |*args, last| ... } click to toggle source

Iterates with whether the item is the last item.

[1,2].each_with_last { |item, is_last| puts [item, is_last] }
# => [1, false] [2, true]
# File lib/with_last/core_ext.rb, line 49
def each_with_last
  return to_enum :each_with_last unless block_given?

  each.with_last { |*args, last| yield(*args, last) }
end