+ 1

Ruby - Why is arr1.length = 3?

arr1 = ["a", "b"] arr2 = ["c","b","a"] arr1 << arr2 puts arr1 puts "#{arr1.length}" As expected, after <<, arr1 = ["a","b","c","b","a"]. Why arr1.length = 3, as if it were a set?

17th Sep 2019, 10:26 AM
Paolo De Nictolis
Paolo De Nictolis - avatar
3 Answers
+ 2
actually, its ["a","b",["c","b","a"]]
17th Sep 2019, 12:12 PM
Choe
Choe - avatar
+ 2
You should do arr1 += arr2
17th Sep 2019, 7:52 PM
Lorenzo Farnararo
Lorenzo Farnararo - avatar
0
do something like this for i in 0...arr2.length arr1 << arr2[i] end
17th Sep 2019, 1:26 PM
Choe
Choe - avatar