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

后端 未结 16 2510
时光取名叫无心
时光取名叫无心 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:53

    It basically execute the method call tag.name on each tags in the array.

    It is a simplified ruby shorthand.

提交回复
热议问题