4 ms·
In Ruby 1.9, or Ruby 1.8 w/ ActiveSupport, you can use the & operator, which coerces it's argument (in this case, a symbol) to a Proc: all_users.select(&:i
by generalk 16y ago
In Ruby 1.9, or Ruby 1.8 w/ ActiveSupport, you can use the & operator, which coerces it's argument (in this case, a symbol) to a Proc:
all_users.select(&:is_admin).map(&:username)
This is a common idiom with a fantastic writeup at http://weblog.raganwald.com/2008/02/1100inject.html http://weblog.raganwald.com/2008/02/1100inject.html
- DanielRibeiro 16y agoActually on ruby 1.8.7 the proc coercion is default. No need for active support. And yeah, ruby underscore is overkill for this trivial example.