Module: Tins::ToProc

Defined in:
lib/tins/to_proc.rb

Overview

This module provides a way to convert symbols into procs using the __send__ method for dynamic method invocation. It was necessary before Ruby 1.9’s built-in Symbol#to_proc functionality. You still can use it for strings, though.

Example Usage:

class String
  include Tins::ToProc
end

["hello", "world"].map(&'upcase')  # => ["HELLO", "WORLD"]

Instance Method Summary collapse

Instance Method Details

#to_procProc

Converts a Symbol into a Proc that sends the symbol’s name to its argument

message to obj with args

Returns:

  • (Proc)

    a Proc that when called will send the symbol’s name as a



19
20
21
22
23
# File 'lib/tins/to_proc.rb', line 19

def to_proc
  lambda do |obj, *args|
    obj.__send__(self, *args)
  end
end