entries/to_a methods

The entries/to_a methods take an enumerable collection and return it in array form.

Number List

@numbers = [1, 0, 3, 2, 5, 4, 7, 6, 9, 8]

# all numbers:
@numbers.entries

Pet Inventory

# leg counts for all pets:
@inventory.entries.map(&:legs)

# leg totals for each pet type, if all pets have 100 in stock:
@inventory.entries(:quantity => 100).map{|pet| pet.legs * pet.quantity}

Pokey Things

# all pokey things:
@pokey_things.seek(0)
@pokey_things.entries.map(&:chomp)

Heroku Log File

# all heroku requests:
@requests.entries

# all heroku requests in simple format:
@requests.entries(:simple)

Leave a Reply

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