Can you supply arguments to the map(&:method) syntax in Ruby?

后端 未结 7 1236
面向向阳花
面向向阳花 2020-11-22 16:59

You\'re probably familiar with the following Ruby shorthand (a is an array):

a.map(&:method)

For example, try the followin

7条回答
  •  清歌不尽
    2020-11-22 17:40

    Short answer: No.

    Following @rkon's answer, you could also do this:

    a = [1,3,5,7,9]
    a.map &->(_) { _ + 2 } # => [3, 5, 7, 9, 11]
    

提交回复
热议问题