I would like to extract hash key values to an array when a condition is met. For example, with hash h I want to extract the keys where the values are "true":
h = { :a => true, :b => false, :c =>true }
I've come up with this:
h.map {|k,v| k if v==true} - [nil]
Any alternatives?
mapandcollectare aliases, notselect.selectdoes different job and in case of Hash returns different type: it returns Hash, while map/collect return Array.