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

Popular posts from this blog

php - Extract Text from HTTP referer -

Receive udp packets in android gstreamer -

authentication - ASP.NET Core 1.0. Bearer Token, cannot access custom claims -