Class: Symbol

Inherits:
Object show all
Defined in:
lib/ruby/jruby_hack.rb

Overview

lib/ruby/symbol.rb

Instance Method Summary collapse

Instance Method Details

#call(receiver, *args) ⇒ Object

Calls self on the given receiver

Examples:

:to_s.call(100)           #=> "100"
:join.call([1,2,3], "-")  #=> "1-2-3"


524
525
526
# File 'lib/ruby/jruby_hack.rb', line 524

def call(receiver, *args)
  receiver.__send__(self, *args)
end

#to_procObject

Returns a proc that calls self on the proc’s parameter

Examples:

[1, 2, 3].map(&:-@)       #=> [-1, -2, -3]
[-1, -2, -3].map(&:abs)   #=> [1, 2, 3]


514
515
516
# File 'lib/ruby/jruby_hack.rb', line 514

def to_proc
  lambda{|*args| args.head.__send__(self, *args.tail) }
end