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 -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -