Module: Enumerable
- Defined in:
- lib/with_last/core_ext.rb
Overview
open core class
Instance Method Summary collapse
-
#each_with_last ⇒ Object
Iterates with whether the item is the last item.
Instance Method Details
#each_with_last ⇒ Object
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]
49 50 51 52 53 |
# 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 |