Sha256: 615fcab655e5aaa4530506153f784f97bede4d102947c4580fcfa09113e37336

Contents?: true

Size: 502 Bytes

Versions: 2

Compression:

Stored size: 502 Bytes

Contents

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

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
activesupport-3.0.pre lib/active_support/core_ext/symbol/to_proc.rb
recliner-0.0.1 vendor/activesupport/lib/active_support/core_ext/symbol/to_proc.rb