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.
Typegraph§
RatStr