Skip to content
class method · added in Ruby 4.0

Ractor.shareable_proc

[T] () { (?) [self: nil] -> T } -> ^(?) [self: nil] -> T
[T, S] (self: S) { (?) [self: S] -> T } -> ^(?) [self: S] -> T
Ractor.shareable_proc(self: nil){} → shareable proc

Returns a shareable copy of the given block’s Proc. The value of self in the Proc will be replaced with the value passed via the self: keyword, or nil if not given.

In a shareable Proc, access to any outer variables if prohibited.

Example
a = 42
Ractor.shareable_proc{ p a }
#=> can not isolate a Proc because it accesses outer variables (a). (ArgumentError)

The value of self in the Proc must be a shareable object.

Example
Ractor.shareable_proc(self: self){}
#=> self should be shareable: main (Ractor::IsolationError)

Ruby version changes

  1. 4.0