From: 7stud -- Date: 2012-12-29T08:08:43+09:00 Subject: Re: Ruby Koans regarding Hashes. 7stud -- wrote in post #1090511: > > > No. Inside the block, the code assigns an array reference to the key. > Then the block returns a reference to the same array. Two references > to the same array. Either one can be used to change the array. Here is > a simple example of that: > > ref1 = {} > ref2 = ref1 > > ref1[:a] = 10 > ref2[:b] = 20 > > p ref1 > > --output:-- > > {:a=>10, :b=>20} > Whoops. An example of two references to the same array would like this: ref1 = [] ref2 = ref1 ref1 << 10 ref2 << 20 p ref1 --output:-- [10, 20] my_hash = {} array_ref = my_hash[:one] = [] array_ref << 'hello' << 'world' --output:-- {:one=>["hello", "world"]} p my_hash -- Posted via http://www.ruby-forum.com/.