Another answer:
ary = [ :apples, :bananas, :strawberries ]
Hash[[*ary.each_with_object(20)]]
# => {:apples=>20, :bananas=>20, :strawberries=>20}
Alternatively (as pointed out by the OP):
ary.each_with_object(20).to_h
# => {:apples=>20, :bananas=>20, :strawberries=>20}
Basically, calling each_with_object
returns an Enumerator
object of pairs consisting of each value and the number 20 (i.e. [:apples, 20], ...
) which can subsequently be converted to a hash.