# Array

**URL:** <https://www.ruby-forum.com/t/array/161293>\
**Category:** Ruby\
**Created:** [February 25, 2009, 5:54am UTC](https://www.ruby-forum.com/t/array/161293 "2009-02-25T05:54:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vetrivel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/dc4da7/32.png) [@vetrivel](https://www.ruby-forum.com/u/vetrivel)\
**Post date:** [February 25, 2009, 5:54am UTC](https://www.ruby-forum.com/t/array/161293/1 "2009-02-25T05:54:01Z")

</div>

How to Join multiple arrays in a single method in ruby  
Ex:  
a= [1 ,2 , 3]  
b = [4,5,6]  
c = [7,8,9]  
Using single method i want b and c array content into the a array.

---

<div class="post-metadata">

**Author:** ![vetrivel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/dc4da7/32.png) [@vetrivel](https://www.ruby-forum.com/u/vetrivel)\
**Post date:** [February 25, 2009, 5:59am UTC](https://www.ruby-forum.com/t/array/161293/2 "2009-02-25T05:59:51Z")

</div>

Vetrivel V. wrote:

> How to Join multiple arrays in a single method in ruby  
> Ex:  
> a= [1 ,2 , 3]  
> b = [4,5,6]  
> c = [7,8,9]  
> Using single method i want b and c array content into the a array.

Hey , what is this ? are you read documentation for ruby or any thing  
else ?.

Answer is ,  
a + b + c

---

<div class="post-metadata">

**Author:** ![vetrivel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/dc4da7/32.png) [@vetrivel](https://www.ruby-forum.com/u/vetrivel)\
**Post date:** [February 25, 2009, 6:05am UTC](https://www.ruby-forum.com/t/array/161293/3 "2009-02-25T06:05:38Z")

</div>

Ashikali A. wrote:

> Vetrivel V. wrote:
> 
> > How to Join multiple arrays in a single method in ruby  
> > Ex:  
> > a= [1 ,2 , 3]  
> > b = [4,5,6]  
> > c = [7,8,9]  
> > Using single method i want b and c array content into the a array.
> 
> Hey , what is this ? are you read documentation for ruby or any thing  
> else ?.
> 
> Answer is ,  
> a + b + c

We can do this .In ruby The ‘+’ is method.You are calling ‘+’ method  
three times.But I have asked using single function we have to do.

---

<div class="post-metadata">

**Author:** ![vetrivel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/dc4da7/32.png) [@vetrivel](https://www.ruby-forum.com/u/vetrivel)\
**Post date:** [February 25, 2009, 6:15am UTC](https://www.ruby-forum.com/t/array/161293/4 "2009-02-25T06:15:31Z")

</div>

Ashikali A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> Hey , what is this ? are you read documentation for ruby or any thing  
> else ?.
> 
> Answer is ,  
> a + b + c

I expect that was what the OP was looking for. But on the other hand,  
your solution involves two methods, not one. One way to do it with one  
method is the following:

require ‘pp’

class Array  
def concat\_multi! \*lists  
lists.each {|list| self.concat(list) }  
end  
end

a = [1, 2, 3]  
b = [4, 5, 6]  
c = [7, 8, 9]  
d = [10, 11]

a.concat\_multi!(b, c, d)

pp a

---

<div class="post-metadata">

**Author:** ![vetrivel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/dc4da7/32.png) [@vetrivel](https://www.ruby-forum.com/u/vetrivel)\
**Post date:** [February 25, 2009, 8:29am UTC](https://www.ruby-forum.com/t/array/161293/5 "2009-02-25T08:29:02Z")

</div>

On Wed, Feb 25, 2009 at 10:34 AM, Vetrivel V.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ashikali A. wrote:
> 
> > Answer is ,  
> > a + b + c
> 
> We can do this .In ruby The ‘+’ is method.You are calling ‘+’ method  
> three times.But I have asked using single function we have to do.

Why? Is this a quiz question? Please explain why it matters that  
it’s a single method call.

Does this work for you?:  
[a, b, c].flatten

Cheers,  
lasitha
