Q:

Ruby program to demonstrate the Array.concat() method

belongs to collection: Ruby Arrays Programs

0

In this program, we will create two arrays of integers. Then we will merge both arrays using the concat() method.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to demonstrate the Array.concat() method is given below. The given program is compiled and executed successfully.

# Ruby program to demonstrate the 
# Array.concat() method

arr1 = [10,20,30,40,50];
arr2 = [70,80];
res = arr1.concat(arr2);

puts "Concatenated Array: \n",res,"\n";

Output:

Concatenated Array: 
10
20
30
40
50
70
80

Explanation:

In the above program, we created two arrays arr1arr2 with some elements. Then we used the concat() method. The concat() method is used to merge two arrays and assign the result to the res. After that, we printed the result.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Ruby Arrays Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Ruby program to remove elements from the array usi... >>
<< Ruby program to remove duplicate elements from the...