Ruby: returning an array of single attributes from an array of objects
You can do this:
animals.collect(&:name)
…to return an array of animal names. This is essentially a shorthand version of:
animals.collect { |animal| animal.name }
You can do this:
animals.collect(&:name)
…to return an array of animal names. This is essentially a shorthand version of:
animals.collect { |animal| animal.name }