How to efficiently concatenate multiple arrays in Ruby?

前端 未结 3 1224
无人及你
无人及你 2021-01-02 02:56

I just wanted to concatenate multiple arrays in Ruby and couldn\'t find a satisfying way to do so.

Example input:

foo = [1, 2, 3]
ba         


        
3条回答
  •  情话喂你
    2021-01-02 03:26

    If you've already determined that multiple concatenation is the fastest method, you can write it nicer using reduce:

    [foo, bar, baz].reduce([], :concat)
    

提交回复
热议问题