Difference between map and collect in Ruby?

后端 未结 6 1413
遥遥无期
遥遥无期 2020-11-28 00:26

I have Googled this and got patchy / contradictory opinions - is there actually any difference between doing a map and doing a collect on an array

6条回答
  •  攒了一身酷
    2020-11-28 01:16

    The collect and collect! methods are aliases to map and map!, so they can be used interchangeably. Here is an easy way to confirm that:

    Array.instance_method(:map) == Array.instance_method(:collect)
     => true
    

提交回复
热议问题