Class: Symbol

Inherits:
Object show all
Defined in:
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"


21
22
23
# File 'lib/ruby/symbol.rb', line 21

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]


10
11
12
# File 'lib/ruby/symbol.rb', line 10

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