tags:

views:

276

answers:

1

Possible Duplicate:
Ruby/Ruby on Rails ampersand colon shortcut

Seen in Railscast #167 :

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

What is this &:name syntax, what does it do ?

I understand what a symbol is, but what other kinds of objects this & can be prepended to ?


Duplicate question : http://stackoverflow.com/questions/1961030/ruby-ruby-on-rails-ampersand-colon-shortcut

+8  A: 

Its shorthand for converting a symbol to a Proc and then executing it (the Proc). This blog post covers it:

http://blog.hasmanythrough.com/2006/3/7/symbol-to-proc-shorthand

Cody Caughlan
Ok, so it would expand to tags.map {|t| t.name }.join(' '). Thanks!
subtenante