# Re: Truncate an array

**URL:** <https://www.ruby-forum.com/t/re-truncate-an-array/100003>\
**Category:** Ruby\
**Created:** [July 26, 2006, 4:48pm UTC](https://www.ruby-forum.com/t/re-truncate-an-array/100003 "2006-07-26T16:48:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [July 26, 2006, 4:48pm UTC](https://www.ruby-forum.com/t/re-truncate-an-array/100003/1 "2006-07-26T16:48:30Z")

</div>

> complains if you assign to it more than once.  
> If it’s not constant, don’t make it a constant.

> 1. We didn’t really truncate the array, just made a new empty one.

Ok, use Array#clear then:

irb(main):014:0\> a = [1,2,3]  
=\> [1, 2, 3]  
irb(main):015:0\> b = a  
=\> [1, 2, 3]  
irb(main):016:0\> a.clear  
=\> []  
irb(main):017:0\> a  
=\> []  
irb(main):018:0\> b  
=\> []

Regards,

Dan

This communication is the property of Qwest and may contain confidential  
or  
privileged information. Unauthorized use of this communication is  
strictly  
prohibited and may be unlawful. If you have received this communication  
in error, please immediately notify the sender by reply e-mail and  
destroy  
all copies of the communication and any attachments.

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [July 26, 2006, 6:10pm UTC](https://www.ruby-forum.com/t/re-truncate-an-array/100003/2 "2006-07-26T18:10:22Z")

</div>

ah, thats the one.
