RbBlockRetention
public enum RbBlockRetention
Control over how Swift closures passed as blocks are retained.
When you pass a Swift closure as a block, for example using
RbObjectAccess.call(_:args:kwArgs:blockRetention:blockCall:)
, RubyGateway
needs some help to understand how Ruby will use the closure.
The easiest thing to get wrong is using .none
when Ruby retains the
block for use later. This causes a hard crash in RbBlockContext.from(raw:)
when Ruby tries to call the block.
Topics
case none
case none
Do not retain the closure. The default, appropriate when the block
is used only during execution of the method it is passed to. For
example #each
.
Declaration
case none
case `self`
case `self`
Retain the closure for as long as the object that owns the method. Use when a method stores a closure in an object property for later use.
Declaration
case `self`
case returned
case returned
Retain the closure for as long as the object returned by the method.
Use when the method is a factory that produces some object and passes
that object the closure. For example Proc#new
.
Declaration
case returned