def insert_array receiver, pos, other
receiver.insert pos, *other
end
insert_array [1, 4], 1, [2, 3]
#โ [1, 2, 3, 4]
, monkeypatching Array:
class Array
def insert_array pos, other
insert pos, *other
end
end
, , . BTW, , , :
[1, [4,5]].insert 1, *[2,3]
#โ [1, 2, 3, [4,5]]
[1, [4,5]].insert(1, [2,3]).flatten
#โ [1, 2, 3, 4, 5]