If I have an array
apple_array = [
#<name: "Bob", apples_eaten: 3>,
#<name: "Robert", apples_eaten: 7>,
#<name: "Bob", apples_eaten: 5>,
#<name: "Rebecca", apples_eaten: 2>,
#<name: "Robert", apples_eaten: 3>
]
how do I return something along the lines of the following, which goes through the array and calculates the total based on one of the attributes in the array?
name: Bob, apples_eaten: 8
name: Robert, apples_eaten: 10
name: Rebecca, apples_eaten: 2
Right now I know how to return the total amount of apples_eaten by calling apple_array.inject(0) { |sum, e| sum + e.apples_eaten }, Is there a way to map that line to each individual name?