Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby seem to reference a variable instead of coping it's value
    text
    copied!<p>Why does the value in my data_dummy hash increase? I’d like to use it to initiate another hash with zero values!</p> <pre><code>fau[f.label][:hash] = data_dummy # ==&gt;{"name 1" =&gt; 0, "name 2" =&gt; 0} but in the second loop it contains data from the first loop e.g. {"name 1" =&gt; 2, "name 2" =&gt; 0} </code></pre> <p>When using the string instead of variable dummy_data the code works as expected.</p> <pre><code>fau[f.label][:hash] = {"name 1" =&gt; 0, "name 2" =&gt; 0} </code></pre> <p>I can't do that because 'name X' is changing....</p> <p>That's strange to me!</p> <p><strong>complete code</strong></p> <pre><code>fau = {} series = [] labels = [{:value =&gt; 0, :text =&gt; ''}] data_dummy = {} source.each do |c| data_dummy[c.name] = 0 end i = 0 data_dummy.each do |k,v| i += 1 labels.push({:value =&gt; i, :text =&gt; k}) end source.each do |s| logger.debug "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" logger.debug "Source: '#{s.name}'|'#{fault_labels[s.fault_id.to_s].label}' =&gt; #{s.cnt}" con_name = s.name #TODO: Cut name (remove location like left,right, ...) f = fault_labels[s.fault_id.to_s] unless fau.has_key?(f.label) # init faults-hash 'fau' fau[f.label] = {:total =&gt; 0, :hash =&gt; {}, :color =&gt; f.color, :name =&gt; f.label} #, :data =&gt; [] # add all connector_names as keys with value = 0 logger.debug "init :hash with #{data_dummy}" # ==&gt;{"name 1" =&gt; 0, "name 2" =&gt; 0} but in the second loop it contains data from the first loop e.g. {"name 1" =&gt; 2, "name 2" =&gt; 0} fau[f.label][:hash] = data_dummy # this way the number of incidents are all in the same order for each fault (first dimension key) # and all get at least a value of 0 end logger.debug "Count up fau['#{f.label}'][:total] = #{fau[f.label][:total]} + #{s.cnt} (where connector '#{s.name}' and fault '#{f.label}')" logger.debug "Count up fau['#{f.label}'][:hash]['#{con_name}'] = #{fau[f.label][:hash][con_name]} + #{s.cnt}" fau[f.label][:total] += s.cnt fau[f.label][:hash][con_name] += s.cnt logger.debug "result :hash with #{fau[f.label][:hash].inspect}}" end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload