I would like to read true objects in an array. Since I can pass the block for counting, the most idiomatic way I found was as follows:
[1, nil, 'foo', false, true].count { |i| i }
But I was wondering if there is a better way, especially using the syntax count(&:something), because passing the full block here looks like a iterator.
AFAIK, there is no method in Ruby truthy?, so I could not find how to do this.
source
share