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:
parent
6839883854
commit
3694227f24
2 changed files with 15 additions and 14 deletions
|
@ -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'
|
||||
|
|
14
activesupport/lib/active_support/core_ext/symbol/to_proc.rb
Normal file
14
activesupport/lib/active_support/core_ext/symbol/to_proc.rb
Normal 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
|
Loading…
Reference in a new issue