class RatStr
class RatStr is Allomorph is Rat {}
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ā¤Ā»
Methods
method new
method new(Rat $i, Str $s)
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"ā¤Ā»
method Capture
method Capture(RatStr:D: --> Capture:D)
Equivalent to Mu.Capture.
method Numeric
multi method Numeric(RatStr:D: --> Rat:D)
multi method Numeric(RatStr:U: --> Rat:D)
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
Returns the Rat value of the RatStr
.
method Real
multi method Real(Real:D: --> Rat:D)
multi method Real(Real:U: --> Rat:D)
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)
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.