BrowserREPL-button-tip-on BrowserREPL-button-tip-off

EditButtonTip 2024-05-28

class RatStr

Dual value rational number and string

class RatStr is Allomorph is Rat {}
Code

RatStr is a dual value type, a subclass of both Allomorph, hence Str, and Rat.

See Allomorph for further details.

my $rat-str = <42.1>;
say $rat-str.^name;       # OUTPUT: «RatStr␤»

my Rat $rat = $rat-str;   # OK!
my Str $str = $rat-str;   # OK!

# ∈ operator cares about object identity
say 42.1 ∈ <42.1 55 1>; # OUTPUT: «False␤»
Code

Methods§

method new§

method new(Rat $i, Str $s)
Code

The constructor requires both the Rat and the Str value, when constructing one directly the values can be whatever is required:

my $f = RatStr.new(42.1, "forty two and a bit");
say +$f; # OUTPUT: «42.1␤»
say ~$f; # OUTPUT: «"forty two and a bit"␤»
Code

method Capture§

method Capture(RatStr:D: --> Capture:D)
Code

Equivalent to Mu.Capture.

method Numeric§

multi method Numeric(RatStr:D: --> Rat:D)
multi method Numeric(RatStr:U: --> Rat:D)
Code

The :D variant returns the numeric portion of the invocant. The :U variant issues a warning about using an uninitialized value in numeric context and then returns value 0.0.

method Rat§

method Rat
Code

Returns the Rat value of the RatStr.

method Real§

multi method Real(Real:D: --> Rat:D)
multi method Real(Real:U: --> Rat:D)
Code

The :D variant returns the numeric portion of the invocant. The :U variant issues a warning about using an uninitialized value in numeric context and then returns value 0.0.

Operators§

infix ===§

multi infix:<===>(RatStr:D $a, RatStr:D $b)
Code

RatStr Value identity operator. Returns True if the Rat values of $a and $b are identical and their Str values are also identical. Returns False otherwise.

Class relation diagram§

Rakudo Type Relation for RatStr RatStr RatStr Allomorph Allomorph RatStr->Allomorph is Rat Rat RatStr->Rat is