All combinations for hash of arrays [duplicate]
问题 This question already has answers here : Turning a Hash of Arrays into an Array of Hashes in Ruby (7 answers) Closed 6 years ago . Summary Given a Hash where some of the values are arrays, how can I get an array of hashes for all possible combinations? Test Case options = { a:[1,2], b:[3,4], c:5 } p options.self_product #=> [{:a=>1, :b=>3, :c=>5}, #=> {:a=>1, :b=>4, :c=>5}, #=> {:a=>2, :b=>3, :c=>5}, #=> {:a=>2, :b=>4, :c=>5}] When the value for a particular key is not an array, it should