Reputation: 27852
I have an array of arrays like this:
[row1, row2, row3]
I need to find how many of those rows are not empty (have some object inside). I know I can do row1.any?, but how would I find how many of those are in the array?
Upvotes: 1
Views: 52
Reputation: 13901
And as usual, remember that .any?
will not give you a hit if you array is filled with false
or nil
.
[[false], [nil], [true], []].count &:any? #=> 1 only one non-empty (true)
Perhaps it is better to do:
[[false], [nil], [true], []].reject(&:empty?).count #=> 3 non-empty (true, nil, false)
Upvotes: 0