From: Hannes Wyss Date: 2006-03-08T18:22:38+09:00 Subject: Re: ridiculous behavoir of Array#push and Array#clear inspect will give you the answer: On 3/8/06, hongseok.yoon@gmail.com wrote: > 1 obj1 = "object1" > 2 obj2 = "object2" > 3 obj3 = "object3" > 4 > 5 arr1 = Array.new > 6 arr2 = Array.new > 7 > 8 arr1 << obj1 > 9 arr1 << obj2 > 10 > 11 arr2 << obj3 > 12 > 13 puts "" 14 puts arr1.inspect -> [ "object1", "object2" ] > 19 puts "" 20 puts arr2.inspect -> [ "object3" ] > 25 arr1.push( arr2 ) > 26 puts "" 27 puts arr1.inspect -> [ "object1", "object2", [ "object3* ] ] # notice that the third Element of arr1 is not obj3, but arr2! > 32 arr2.clear # fine, emptying arr2... > 33 puts "" > 34 > 35 puts "" 36 puts arr2.inspect -> [ ] > 41 puts "" 42 puts arr1.inspect -> [ "object1", "object2", [ ] ] # the third Element of arr1 is still arr2, it just has been cleared, # so not a trace of obj3... > Yes, I can use clone() method for Array#push. But before, I hope to > know the reason why RUBY's Array#push method works like above. ...or you could do: 25 arr1.concat( arr2 ) -> [ "object1", "object2", "object3" ] for any questions like that: try irb - I can only recommend it.. hth Hannes