RbRational
public struct RbRational: RbObjectConvertible
A simple interface to Ruby’s rational number support.
This is not a Swift rational number library. It could be used as an interface between one such and Ruby.
Ruby represents rational numbers internally as a positive or negative
integer numerator and a positive integer denominator. Instances of this
RbRational
type converted from Ruby objects follow these rules; instances
produced by Swift code using the RbRational.init(numerator:denominator:)
method may not.
let myRat = RbRational(numerator: myFractionTop, denominator: myFractionBot)
let resultObj = myRubyService.call("addFinalSample", args: [myRat])
let myRatResult = RbRational(resultObj)
Topics
var numerator: Double
var numerator: Double
var denominator: Double
var denominator: Double
init(numerator: Double, denominator: Double)
init(numerator: Double, denominator: Double)
init?(RbObject)
init?(RbObject)
Create a rational number from a Ruby object.
This calls #to_r
before extracting the parts so can
be passed various types of Ruby object.
Returns nil
if the object cannot be converted or if its fractional
parts parts cannot be converted to Swift Double
s.
See RbError.history
to see why a conversion failed.
Declaration
public init?(_ value: RbObject)
init?(any RbObjectConvertible)
init?(any RbObjectConvertible)
Convert some Swift data type to a rational.
This is a convenience wrapper that lets you access Ruby’s rational library directly from Swift types, for example:
let rat = RbRational(0.3)
Declaration
public init?(_ value: any RbObjectConvertible)
var rubyObject: RbObject
var rubyObject: RbObject
Get a Ruby version of an RbRational
.
This can theoretically produce RbObject.nilObject
if the environment
has been nobbled in some way.
Declaration
public var rubyObject: RbObject { get }