1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Break out Symbol#to_proc as a future-ruby extension

This commit is contained in:
Jeremy Kemper 2009-05-20 17:10:10 -07:00
parent 6839883854
commit 3694227f24
2 changed files with 15 additions and 14 deletions

View file

@ -1,14 +1 @@
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
require 'active_support/core_ext/symbol/to_proc'

View file

@ -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