On Wed, Mar 12, 2008 at 12:03 AM, Adam Akhtar <adamtemporary / gmail.com> wrote:
> err on a similiar note if i have a hash like the one above and i do this
>
>  temp = template
>
>  if i then modify temp say using temp.insert()
>
>  will it also modify the hash?

Let's try:

irb(main):001:0> a = {:a => 1, :b => 2}
=> {:a=>1, :b=>2}
irb(main):002:0> b = a
=> {:a=>1, :b=>2}
irb(main):003:0> b[:c] = 3
=> 3
irb(main):004:0> a
=> {:c=>3, :a=>1, :b=>2}
irb(main):005:0>

BTW, I couldn't find an insert method for hash, so I used []=

The reason of the above behaviour is that when you do this:

temp = template

is that you now have two variables referencing the same object.
So any change done through any of those variables will change the same
underlying object, thus
making the new value available through the other variable.

There was an analogy about variables being post-it notes attached to
the objects.
An assignment as the above just puts a post-it note with the text
"temp" on the hash.

Jesus.