I want to AND or OR all the elements in an array, but with some control, as shown via the hash element selection. Here is the behavior that I wish to achieve:
a = [{:a => true}, {:a => false}]
a.and_map{ |hash_element| hash_element[:a] }
#=> false
a.or_map{ |hash_element| hash_element[:a] }
#=> true
Is there a slick, clean way to do this in Ruby?
You can use
all?andany?for that: