Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Method#call

(?) -> untyped
call(...) → obj

Invokes self with the specified arguments, returning the method’s return value.

Example
m = 12.method("+")
m.call(3)    #=> 15
m.call(20)   #=> 32

Using Method#=== allows a method object to be the target of a when clause in a case statement.

Example
require 'prime'

case 1373
when Prime.method(:prime?)
  # ...
end
See also #box #clone #arity #curry also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0