Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Proc#===
(?) -> untyped
===(*args)
proc.c
View on GitHub ↗
0
static VALUE
proc_call(int argc, VALUE *argv, VALUE procval)
{
/* removed */
}
Alias of #call
Invokes the block, setting the block’s parameters to the arguments using something close to method calling semantics. Returns the value of the last expression evaluated in the block.
Example
a_proc = Proc.new {|scalar, *values| values.map {|value| value*scalar } } a_proc.call(9, 1, 2, 3) #=> [9, 18, 27] a_proc[9, 1, 2, 3] #=> [9, 18, 27] a_proc.(9, 1, 2, 3) #=> [9, 18, 27] a_proc.yield(9, 1, 2, 3) #=> [9, 18, 27]
Note that prc.() invokes prc.call() with the parameters given. It’s syntactic sugar to hide “call”.
For procs created using lambda or ->() an error is generated if the wrong number of parameters are passed to the proc. For procs created using Proc.new or Kernel.proc, extra parameters are silently discarded and missing parameters are set to nil.
Example
a_proc = proc {|a,b| [a,b] } a_proc.call(1) #=> [1, nil] a_proc = lambda {|a,b| [a,b] } a_proc.call(1) # ArgumentError: wrong number of arguments (given 1, expected 2)
See also Proc#lambda?.