All possible combinations from a hash of arrays in Ruby

后端 未结 4 1998
忘掉有多难
忘掉有多难 2021-02-05 08:01

What I have:

Let\'s say I have a hash like this, with various values belonging to one parameter.

a = {}
a[:bitrate] = [\"100\", \"500\", \"1000\"]
a[:f         


        
4条回答
  •  盖世英雄少女心
    2021-02-05 08:30

    Just FYI I took fl00r's approach and monkey-patched it. I like it a bit better.

    class Hash
      def product
        product = values[0].product(*values[1..-1])
        product.map{|p| Hash[keys.zip p]}
      end
    end
    

提交回复
热议问题