ruby - How to insert an array in the middle of an array? -
i have ruby array [1, 4]. want insert array [2, 3] in middle becomes [1, 2, 3, 4]. can achieve [1, 4].insert(1, [2, 3]).flatten, there better way this?
you following way.
[1,4].insert(1,*[2,3]) the insert() method handles multiple parameters. therefore can convert array parameters splat operator *.
Comments
Post a Comment