cycle method

The cycle method calls the given block for each element in the collection, the number of times specified.

Pet Inventory

# print pet names, twice:
inventory.cycle(2){|pet| puts pet.name}

# output
# dog
# cat
# fish
# scorpion
# beetle
# monkey
# rock
# dog
# cat
# fish
# scorpion
# beetle
# monkey
# rock

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>