Ticket #8818: sym_to_proc_performance_improvement.patch
| File sym_to_proc_performance_improvement.patch, 0.8 kB (added by lifofifo, 2 years ago) |
|---|
-
activesupport/lib/active_support/core_ext/symbol.rb
old new 1 1 class Symbol 2 # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples:2 # Turns the symbol into a simple lambda, which is especially useful for enumerations. Examples: 3 3 # 4 4 # # The same as people.collect { |p| p.name } 5 5 # people.collect(&:name) … … 7 7 # # The same as people.select { |p| p.manager? }.collect { |p| p.salary } 8 8 # people.select(&:manager?).collect(&:salary) 9 9 def to_proc 10 Proc.new { |*args| args.shift.__send__(self, *args)}10 lambda { |obj| obj.send self } 11 11 end 12 12 end