I have an array of Assignment objects that I create from a database call:
@assignments = @player.assignments
I want to count them with this:
@assignments.count {|x| x.sets == 0.0}
This should count the number of assignments with 0.0 sets. However, this always returns the total number of objects in @assignments. I have checked that
@assignments.each {|x| puts x.sets == 0.0}
does not return true in all the cases. Any clues?
Edit>
@assignments.map(&:sets)
=> [35.0, 120.0, 0.0, 0.0, 0.0, 0.0, 0.0, 12.0, 75.0, 0.0, 0.0, 0.0, 0.0]
selectfirst and thencount.@assignments.map(&:sets)?[1] pry(main)> assignments = [35.0, 120.0, 0.0, 0.0, 0.0, 0.0, 0.0, 12.0, 75.0, 0.0, 0.0, 0.0, 0.0] => [35.0, 120.0, 0.0, 0.0, 0.0, 0.0, 0.0, 12.0, 75.0, 0.0, 0.0, 0.0, 0.0] [2] pry(main)> assignments.count {|x| x == 0.0} => 9 [3] pry(main)> assignments.count => 13