Ruby or Ruby on Rails group_by on dynamically changing parameters
<p>I want to change group_by parameters based on user input.
Example:
Data on which i am going to group:</p>

<pre><code>result = [{"result_1"=&gt;"01","result_2"=&gt;"August","result_3"=&gt;"2016","result_4"=&gt;264},{"result_1"=&gt;"02","result_2"=&gt;"August","result_3"=&gt;"2016","result_4"=&gt;49},{"result_1"=&gt;"03","result_2"=&gt;"August","result_3"=&gt;"2016","result_4"=&gt;53}]
</code></pre>

<p>I know how a ruby group_by works with multiple parameters.</p>

<p>To group_by on result_1 and result_2.It can be done this way:</p>

<pre><code>result.group_by{|h| [h["result_1"],h["result_2"]}
</code></pre>

<p>Above code groups the data based on result_1 and result_2.Here the parameters are hard_coded.
I want group_by based on parameters passed dynamically.As</p>

<pre><code>dynamic_parameter = ["result_3","result_4"]
</code></pre>

<p>I want group_by to be as </p>

<pre><code>result.group_by{|h| [h["result_3"],h["result_4"]]}
</code></pre>

<p>i want to do it as roughly:</p>

<pre><code>dynamic_parameters.each do |parameter|
    result.group_by{|h| [h[parameters]}
end
</code></pre>

<p>or similar to:</p>

<pre><code>result.group_by{|h| [h[parameters[0]],h[parameters[1]]}
</code></pre>

<p>These result_3 and result_4 parameters are based on dynamic_parameter array values.</p>

<p>Note: Group_by should vary based on the array elements.</p>