# Question about Array#\*

**URL:** <https://www.ruby-forum.com/t/question-about-array/132744>\
**Category:** Ruby\
**Created:** [March 24, 2008, 10:35am UTC](https://www.ruby-forum.com/t/question-about-array/132744 "2008-03-24T10:35:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Magicloud\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@Magicloud\_M](https://www.ruby-forum.com/u/Magicloud_M)\
**Post date:** [March 24, 2008, 10:35am UTC](https://www.ruby-forum.com/t/question-about-array/132744/1 "2008-03-24T10:35:00Z")

</div>

Hello,  
In `ri 'Array#*'`, it says that the result is the concatenation of  
copies of self if the argument is an int.  
So, it is “COPY”.  
Then why something like ‘[[0]] \* 10’, returns an array, that each  
element is a pointer to the first element?  
Does this mean “copy of an Array” is just a duplicated pointer?

Thanks.

---

<div class="post-metadata">

**Author:** ![Magicloud\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@Magicloud\_M](https://www.ruby-forum.com/u/Magicloud_M)\
**Post date:** [March 24, 2008, 10:46am UTC](https://www.ruby-forum.com/t/question-about-array/132744/2 "2008-03-24T10:46:44Z")

</div>

On Monday 24 March 2008, Magicloud M. wrote:

> Hello,  
> In `ri 'Array#*'`, it says that the result is the concatenation of  
> copies of self if the argument is an int.  
> So, it is “COPY”.  
> Then why something like ‘[[0]] \* 10’, returns an array, that each  
> element is a pointer to the first element?  
> Does this mean “copy of an Array” is just a duplicated pointer?
> 
> Thanks.

I think that here the word “copy” has the same meaning it has in clone  
and  
dup, that is it means a shallow copy: the array itself is copied, but  
its  
contents aren’t. In other words, what you get using Array#\* with a  
number is  
an array of size n times the original one, whose contents are the  
contents of  
the original array repeated n times.

I hope this helps

Stefano

---

<div class="post-metadata">

**Author:** ![Magicloud\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e47774/32.png) [@Magicloud\_M](https://www.ruby-forum.com/u/Magicloud_M)\
**Post date:** [March 24, 2008, 11:22am UTC](https://www.ruby-forum.com/t/question-about-array/132744/3 "2008-03-24T11:22:40Z")

</div>

In source, I got this: MEMCPY(RARRAY(ary2)-\>ptr+i, RARRAY(ary)-\>ptr,  
VALUE, RARRAY(ary)-\>len);  
So, I just got a bunch of pointer to the same object…
