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

# 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 *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>