What does map(&:name) mean in Ruby?

后端 未结 16 2858
时光取名叫无心
时光取名叫无心 2020-11-21 05:34

I found this code in a RailsCast:

def tag_names
  @tag_names || tags.map(&:name).join(\' \')
end

What does the (&:name)

16条回答
  •  半阙折子戏
    2020-11-21 05:59

    (&:name) is short for (&:name.to_proc) it is same as tags.map{ |t| t.name }.join(' ')

    to_proc is actually implemented in C

提交回复
热议问题