=begin pod

=TITLE class RatStr

=SUBTITLE Dual Value Rational number and String

    class RatStr is Rat is Str {}

The dual value types (often referred to as L<allomorphs|/language/glossary#Allomorph>)
allow for the representation of a value as both a string and a numeric type, typically
they will be created for you when the context is "stringy" but they can be determined
to be numbers, such as in some L<quoting constructs|/language/quoting>:

    my $f = <42.1>; say $f.WHAT; # (RatStr)

A C<RatStr> can be used interchangeably where one might use a L<Str|/type/Str> or a
L<Rat|/type/Rat> :

    my $f = <42.1>;
    my $i = $f + 0.1;
    my $s = $f ~ " and a bit more";

=head1 Methods

=head2 method new

    method new(Rat $i, Str $s)

The constructor requires both the C<Rat> and the C<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; # -> 42.1
    say ~$f; # -> "forty two and a bit"

=head2 method Numeric

    method Numeric

The numeric coercion is applied when the C<RatStr> is used in a numeric context,
such as a numeric comparison or smart match against a numeric value. It will return
the C<Rat> value.

=head2 method Rat

    method Rat

Returns the C<Rat> value of the C<RatStr>.

=head2 method Str

Returns the string value of the C<RatStr>.

=head1 Operators

=head2 infix cmp

    multi sub infix:<cmp>(RatStr:D $a, RatStr:D $b)

Compare two C<RatStr> objects.  The comparison is done on the C<Rat> value first and
then on the C<Str> value. If you want to compare in a different order then you would
coerce to the C<Rat> or C<Str> values first:

    my $f = RatStr.new(42.1, "smaller");
    my $g = RatStr.new(43.1, "larger");
    say $f cmp $g;          # Less
    say $f.Str cmp $g.Str;  # More

=end pod

# vim: expandtab shiftwidth=4 ft=perl6
