diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-05-20 17:10:10 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-05-20 18:12:44 -0700 |
commit | 3694227f24d0f220c0ce7ef6c7f51598e2715d2d (patch) | |
tree | d9f68a8e73b0d7d105bc0549c3cc4fea0595daf5 /activesupport/lib/active_support/core_ext/symbol/to_proc.rb | |
parent | 68398838544a778244e6028f2c30deb7313ea0b2 (diff) | |
download | rails-3694227f24d0f220c0ce7ef6c7f51598e2715d2d.tar.gz rails-3694227f24d0f220c0ce7ef6c7f51598e2715d2d.tar.bz2 rails-3694227f24d0f220c0ce7ef6c7f51598e2715d2d.zip |
Break out Symbol#to_proc as a future-ruby extension
Diffstat (limited to 'activesupport/lib/active_support/core_ext/symbol/to_proc.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/symbol/to_proc.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/symbol/to_proc.rb b/activesupport/lib/active_support/core_ext/symbol/to_proc.rb new file mode 100644 index 0000000000..520369452b --- /dev/null +++ b/activesupport/lib/active_support/core_ext/symbol/to_proc.rb @@ -0,0 +1,14 @@ +class Symbol + # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples: + # + # # The same as people.collect { |p| p.name } + # people.collect(&:name) + # + # # The same as people.select { |p| p.manager? }.collect { |p| p.salary } + # people.select(&:manager?).collect(&:salary) + # + # This is a builtin method in Ruby 1.8.7 and later. + def to_proc + Proc.new { |*args| args.shift.__send__(self, *args) } + end unless :to_proc.respond_to?(:to_proc) +end |