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 *