File tree Expand file tree Collapse file tree 1 file changed +17
-11
lines changed Expand file tree Collapse file tree 1 file changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -104,8 +104,8 @@ through the C<has> keyword, and behaviors introduced through the C<method>
104
104
keyword.
105
105
106
106
X < |type object >
107
- X < |defined >
108
- X < |.defined >
107
+ X < |DEFINITE >
108
+ X < |.DEFINITE >
109
109
110
110
Declaring a class creates a new I < type object > which, by default, is installed into
111
111
the current package (just like a variable declared with C < our > scope). This
@@ -115,16 +115,22 @@ classes. The example above uses the class name C<Task> so that other code can
115
115
refer to it later, such as to create class instances by calling the C < new >
116
116
method.
117
117
118
- Type objects are I < undefined > , in the sense that they return C < False > if you
119
- call the C < .defined > method on them. You can use this method to find out if
120
- a given object is a type object or not:
118
+ You can use C < .DEFINITE > method to find out if what you have is an instance
119
+ or a type object:
121
120
122
- my $obj = Int;
123
- if $obj.defined {
124
- say "Ordinary, user-defined object";
125
- } else {
126
- say "Type object";
127
- }
121
+ say Int.DEFINITE; # False (type object)
122
+ say 426.DEFINITE; # True (instance)
123
+
124
+ class Foo {};
125
+ say Foo.DEFINITE; # False (type object)
126
+ say Foo.new.DEFINITE; # True (instance)
127
+
128
+ You can also use type smileys to only accept instances or type objects:
129
+
130
+ multi foo (Int:U) { "It's a type object!" }
131
+ multi foo (Int:D) { "It's an instance!" }
132
+ say foo Int; # It's a type object!
133
+ say foo 42; # It's an instance!
128
134
129
135
= head1 State
130
136
You can’t perform that action at this time.
0 commit comments