map(&:name)在Ruby中意味著什么?我在鐵路:def tag_names @tag_names || tags.map(&:name).join(' ')end是什么(&:name)在……里面map(&:name)刻薄?
4 回答

楊__羊羊
TA貢獻(xiàn)1943條經(jīng)驗(yàn) 獲得超7個(gè)贊
#to_proc
#to_proc
class Array def to_proc proc { |receiver| receiver.send *self } endend# And then...[ 'Hello', 'Goodbye' ].map &[ :+, ' world!' ]#=> ["Hello world!", "Goodbye world!"]
&
to_proc
#to_proc
[ 'Hello', 'Goodbye' ].map { |receiver| receiver.send( :+, ' world!' ) }
- 4 回答
- 0 關(guān)注
- 705 瀏覽
添加回答
舉報(bào)
0/150
提交
取消