#--
# Credit goes to Florian Gross (flgr) for orignal version.
# Credit goes to Nobuhiro Imai for latest version.
#++

class Symbol

  # Turn a symbol into a proc calling the method to
  # which it refers.
  #
  #   up = :upcase.to_proc
  #   up.call("hello")  #=> HELLO
  #
  # More useful is the fact that this allows <tt>&</tt>
  # to be used to coerce Symbol into Proc. 
  #
  #   %w{foo bar qux}.map(&:upcase)   #=> ["FOO","BAR","QUX"]
  #   [1, 2, 3].inject(&:+)           #=> 6
  #

  def to_proc
    Proc.new{|*args| args.shift.__send__(self, *args)}
  end

end



#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCSymbol < Test::Unit::TestCase

    def test_001
      assert_instance_of(Proc, up = :upcase.to_proc )
      assert_equal( "HELLO", up.call("hello") )
    end

    def test_002
      q = [[1,2,3], [4,5,6], [7,8,9]].map(&:reverse)
      a = [[3, 2, 1], [6, 5, 4], [9, 8, 7]]
      assert_equal( a, q )
    end

  end

=end
