With my array of hashes:
data = [{:bool => true, :val => 5}, {:bool => false, :val => 9}, {:bool => true, :val => 1}]
I would like to iterate through the data and retrieve an array of values only. I can do:
data.map{|x| x[:val] if x[:bool]}
which returns:
[5, nil, 1]
But this method requires an additional .compact call to get rid of the nil values.
Is there a better way of achieving this?
selectand notcollect?