RbMethod
public struct RbMethod: Sendable
This offers useful services to Swift implementations of Ruby methods.
You do not create instances of this type: instead, RubyGateway creates instances and passes them to method callbacks.
Topics
var rubySelf: RbObject
var rubySelf: RbObject
The object against which the method has been invoked.
Declaration
public let rubySelf: RbObject
var args: RbMethodArgs
var args: RbMethodArgs
The arguments passed to the method, decoded according to the method’s RbMethodArgsSpec
.
Declaration
public let args: RbMethodArgs
var argsSpec: RbMethodArgsSpec
var argsSpec: RbMethodArgsSpec
The method’s arguments specification, originally set by the user at the point the method was defined.
Declaration
public let argsSpec: RbMethodArgsSpec
var isBlockGiven: Bool
var isBlockGiven: Bool
func needsBlock()
func needsBlock()
Raise an exception if the method has not been passed a block.
Declaration
public func needsBlock() throws
func yieldBlock(args: [(any RbObjectConvertible)?], kwArgs: KeyValuePairs<String, (any RbObjectConvertible)?>) -> RbObject
func yieldBlock(args: [(any RbObjectConvertible)?], kwArgs: KeyValuePairs<String, (any RbObjectConvertible)?>) -> RbObject
Invoke the method’s block and get the result.
If the method was not passed a block then a Ruby exception is raised.
Declaration
@discardableResult
public func yieldBlock(
args: [(any RbObjectConvertible)?] = [],
kwArgs: KeyValuePairs<String, (any RbObjectConvertible)?> = [:]
) throws -> RbObject
Parameters
args |
The arguments to pass to the block, none by default. |
Throws
RbError.rubyException(_:)
if the block raises an exception.
RbError.rubyJump(_:)
if the block does return
or break
.
You should not attempt to handle rubyJump
errors: rethrow them
back to Ruby as soon as possible.
Return Value
The value returned by the block.
func captureBlock() -> RbObject
func captureBlock() -> RbObject
Get the method’s block as a Ruby Proc
.
If you want to just call the block then use yieldBlock(args:kwArgs:)
. Use this method
to store the block or do things to it.
Declaration
public func captureBlock() throws -> RbObject
Throws
RbError.rubyException(_:)
if the method does not have a block.
Return Value
An RbObject
for a Proc
object wrapping the passed block.
func callSuper(args: [(any RbObjectConvertible)?], kwArgs: KeyValuePairs<String, (any RbObjectConvertible)?>) -> RbObject
func callSuper(args: [(any RbObjectConvertible)?], kwArgs: KeyValuePairs<String, (any RbObjectConvertible)?>) -> RbObject
Call the overridden version of the current method.
The current active block, if any, is passed on to the superclass method. There is no RubyGateway equivalent to Ruby’s ‘raw super’ keyword, you must always explicitly specify the arguments to pass on.
If there is no matching superclass method to call then Ruby raises a
NoMethodError
that is thrown as an RbError.rubyException(_:)
.
Declaration
public func callSuper(
args: [(any RbObjectConvertible)?] = [],
kwArgs: KeyValuePairs<String, (any RbObjectConvertible)?> = [:]
) throws -> RbObject
Parameters
args |
Positional arguments to pass to the superclass method. |
kwArgs |
Keyword arguments to pass to the superclass method. |
Throws
RbError.rubyException(_:)
if there is a Ruby exception.
RbError.duplicateKwArg(_:)
if there are duplicate keywords in kwArgs
.
Return Value
The value returned by the superclass method.