Skip to content
Tags

,

Map tip

May 24, 2011
  Product.all.map(&:name)

returns an array of names of all products.

Apparently

 &:name

calls

 :name.to_proc
some_method(&expression) will pass expression to some_method as the block param. similar to some_method do …. end or some_method { … }. To do that , erpxession should be either a pProc or respond to to_proc. :name is a Symbol, so .map(&:name) calls :name.to_proc and passes the reslut as a block to map.
Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: