Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So after 1 hour of brainstorming..I have come to the conclusion that in the multi dimensional hashes, the dup generates the same object_id for each key which is in turn referring to the hash whereas in the single dimensional hash, the object_ids are similar initially but when we make any changes to the object the Ruby would assign new object_id to the hash keys..</p> <p>Look at the following code</p> <pre><code>h = { :a =&gt; "a", :b =&gt; "b" } # =&gt; {:a=&gt;"a", :b=&gt;"b"} h_clone = h.dup #=&gt; {:a=&gt;"a", :b=&gt;"b"} h.object_id #=&gt; 73436330 h_clone.object_id #=&gt; 73295920 h[:a].object_id #=&gt; 73436400 h_clone[:a].object_id #=&gt; 73436400 h[:b].object_id #=&gt; 73436380 h_clone[:b].object_id #=&gt; 73436380 h_clone[:b] = "New B" #=&gt; "New B" h_clone[:b].object_id #=&gt; 74385280 h.object_id #=&gt; 73436330 h_clone.object_id #=&gt; 73295920 h[:a].object_id #=&gt; 73436400 h_clone[:a].object_id #=&gt; 73436400 </code></pre> <p>Look the following code for the multidimensional array</p> <pre><code>h = { :one =&gt; { :a =&gt; "a", :b =&gt; "b" } } #=&gt; {:one=&gt;{:a=&gt;"a", :b=&gt;"b"}} h_copy = h.dup #=&gt; {:one=&gt;{:a=&gt;"a", :b=&gt;"b"}} h_copy.object_id #=&gt; 80410620 h.object_id #=&gt; 80552610 h[:one].object_id #=&gt; 80552620 h_copy[:one].object_id #=&gt; 80552620 h[:one][:a].object_id #=&gt; 80552740 h_copy[:one][:a].object_id #=&gt; 80552740 h[:one][:b].object_id #=&gt; 80552700 h_copy[:one][:b].object_id #=&gt; 80552700 h_copy[:one][:b] = "New B" #=&gt; "New B" h_copy #=&gt; {:one=&gt;{:a=&gt;"a", :b=&gt;"New B"}} h #=&gt; {:one=&gt;{:a=&gt;"a", :b=&gt;"New B"}} h.object_id #=&gt; 80552610 h_copy.object_id #=&gt; 80410620 h[:one].object_id #=&gt; 80552620 h_copy[:one].object_id #=&gt; 80552620 h[:one][:b].object_id #=&gt; 81558770 h_copy[:one][:b].object_id #=&gt; 81558770 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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