views:

1813

answers:

3
+4  A: 

It's shorthand for tags.map { |tag| tag.name }.join(' ')

Oliver N.
Nope, it's in Ruby 1.8.7 and above.
Chuck
collimarco
@Chuck thanks, reverted for correctness.
Oliver N.
Chuck
+6  A: 

It's equivalent to

def tag_names
  @tag_names || tags.map { |tag| tag.name }.join(' ')
end
Ben Alpert
+19  A: 

It's shorthand for tags.map(:name.to_proc).join(' ')

If foo is an object with a to_proc method, then you can pass it to a method as &foo, which will call foo.to_proc and use that as the method's block.

The Symbol#to_proc method was originally added by ActiveSupport but has been integrated into Ruby 1.8.7. This is its implementation:

class Symbol
  def to_proc
    Proc.new do |obj, *args|
      obj.send self, *args
    end
  end
end
jleedev
This is a better answer than mine.
Oliver N.
tags.map(:name.to_proc) is itself a shorthand for tags.map { |tag| tag.name }
Simone Carletti