File: active_support/core_ext/symbol.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: <Built-in Module>
  class: Symbol#2
inherits from
  Object ( Builtin-Module )
has properties
method: to_proc #10

Class Hierarchy

Object ( Builtin-Module )
  Symbol    #2

Code

   1  unless :to_proc.respond_to?(:to_proc)
   2    class Symbol
   3      # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples:
   4      #
   5      #   # The same as people.collect { |p| p.name }
   6      #   people.collect(&:name)
   7      #
   8      #   # The same as people.select { |p| p.manager? }.collect { |p| p.salary }
   9      #   people.select(&:manager?).collect(&:salary)
  10      def to_proc
  11        Proc.new { |*args| args.shift.__send__(self, *args) }
  12      end
  13    end
  14  end