Skip to content

Commit

Permalink
Break out Symbol#to_proc as a future-ruby extension
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy committed May 21, 2009
1 parent 6839883 commit 3694227
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
15 changes: 1 addition & 14 deletions activesupport/lib/active_support/core_ext/symbol.rb
@@ -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 changes: 14 additions & 0 deletions 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

0 comments on commit 3694227

Please sign in to comment.