You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/Type/Mu.pod6
+10-5Lines changed: 10 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -48,16 +48,17 @@ invokes the C<.defined> method on the object and returns its result.
48
48
multi method isa(Mu $type --> Bool:D)
49
49
multi method isa(Str:D $type --> Bool:D)
50
50
51
-
Returns C<True> if the invocant is an instance of class C<$type>, a subset type or a derived class (through inheritance) of C<$type>.
51
+
Returns C<True> if the invocant is an instance of class C<$type>, a subset type or a derived class (through inheritance) of C<$type>. Unlike L<C<does>|/routine/does#(Mu)_routine_does>, which includes roles.
52
52
53
53
my $i = 17;
54
54
say $i.isa("Int"); # OUTPUT: «True»
55
55
say $i.isa(Any); # OUTPUT: «True»
56
+
role Truish {};
57
+
my $but-true = 0 but Truish;
58
+
say $but-true.^name; # OUTPUT: «Int+{Truish}»
59
+
say $but-true.does(Truish); # OUTPUT: «True»
60
+
say $but-true.isa(Truish); # OUTPUT: «False»
56
61
57
-
A more idiomatic way to do this is to use the smartmatch operator L<~~|/routine/~~> instead.
58
-
59
-
my $s = "String";
60
-
say $s ~~ Str; # OUTPUT: «True»
61
62
62
63
=head2routine does
63
64
@@ -70,6 +71,10 @@ Returns C<True> if and only if the invocant conforms to type C<$type>.
70
71
say $d.does(Any); # True (Date is a subclass of Any)
71
72
say $d.does(DateTime); # False (Date is not a subclass of DateTime)
72
73
74
+
Unlike L<C<isa>|https://docs.perl6.org/routine/isa#(Mu)_routine_isa>, which returns C<True> only for superclasses, C<does> includes both superclasses and roles.
75
+
76
+
say $d.isa(Dateish); # OUTPUT: «False»
77
+
73
78
Using the smart match operator L<~~|/routine/~~> is a more idiomatic alternative.
0 commit comments