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 - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -