RbComplex

Swift
public struct RbComplex: RbObjectConvertible

A simple interface to Ruby’s complex number support.

This is not a Swift complex number library. It could be used as an interface between one such and Ruby.

Ruby always represents complex numbers internally using rectangular coordinates so this type does not offer any direct support for polar coordinates.


Topics

var real: Double

The real part of the complex number.

Declaration
Swift
public let real: Double

var imaginary: Double

The imaginary part of the complex number.

Declaration
Swift
public let imaginary: Double

init(real: Double, imaginary: Double)

Create a new complex number from real and imaginary parts.

Declaration
Swift
public init(real: Double, imaginary: Double)

init?(RbObject)

Create a complex number from a Ruby object.

This calls #to_c before extracting real and imaginary parts so can be passed various types of Ruby object.

Returns nil if the object cannot be converted or if its real and imaginary parts cannot be converted to Swift Doubles. See RbError.history to see why a conversion failed.

Declaration
Swift
public init?(_ value: RbObject)

init?(any RbObjectConvertible)

Convert some Swift data type to a complex number.

This is a convenience wrapper that lets you access Ruby’s library directly from Swift types, for example:

let compl = RbComplex("1+2.3i")
Declaration
Swift
public init?(_ value: any RbObjectConvertible)

var rubyObject: RbObject

Get a Ruby version of an RbComplex.

This can theoretically produce RbObject.nilObject if the Complex class has been nobbled in some way.

Declaration
Swift
public var rubyObject: RbObject { get }