Why does Array#each return an array with the same elements?

后端 未结 4 1875
名媛妹妹
名媛妹妹 2021-02-18 14:21

I\'m learning the details of how each works in ruby, and I tried out the following line of code:

p [1,2,3,4,5].each { |element| el }
4条回答
  •  难免孤独
    2021-02-18 14:45

    All methods return something. Even if it's just a nil object, it returns something.

    It may as well return the original object rather than return nil.

提交回复
热议问题