I found this code in a RailsCast:
def tag_names
@tag_names || tags.map(&:name).join(' ')
end
What does the (&:name)
in map(&:name)
mean?
I found this code in a RailsCast:
def tag_names
@tag_names || tags.map(&:name).join(' ')
end
What does the (&:name)
in map(&:name)
mean?
(&:name) is short for (&:name.to_proc) it is same as
tags.map{ |t| t.name }.join(' ')
to_proc is actually implemented in C
is The same as
&:name
just uses the symbol as the method name to be called.