Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8812: enum_to_proc_note.patch

File enum_to_proc_note.patch, 0.7 kB (added by lifofifo, 2 years ago)

Add a performance note for usages like map(&:name)

  • activesupport/lib/active_support/core_ext/symbol.rb

    old new  
    66  # 
    77  #   # The same as people.select { |p| p.manager? }.collect { |p| p.salary } 
    88  #   people.select(&:manager?).collect(&:salary) 
     9  #  
     10  #   PERFORMANCE ISSUE : The enumerations shortcut explained above, shouldn't be used for fairly large sized collections as  
     11  #                       it can have serious performance implications. 
     12  #  
    913  def to_proc 
    1014    Proc.new { |*args| args.shift.__send__(self, *args) } 
    1115  end