each_entry method

The each_entry method takes an enumerable collection and yields each element for processing.

View these examples as a runnable ruby script on GitHub.

Number List

class NumberList
  include Enumerable
  
  def each
    yield 1
    yield 2, 3
    yield 4
  end
end

# cycle through each entry:
NumberList.new.each_entry{|number_or_numbers| p number_or_numbers}

# output:
# 1
# [2, 3]
# 4

Leave a Reply

Your email address will not be published. Required fields are marked *