Skip to content

Commit a516adf

Browse files
authored
Clairfy type object/instance .defined thing
Toss .defined and use better methods
1 parent 88240a9 commit a516adf

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

doc/Language/classtut.pod6

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ through the C<has> keyword, and behaviors introduced through the C<method>
104104
keyword.
105105
106106
X<|type object>
107-
X<|defined>
108-
X<|.defined>
107+
X<|DEFINITE>
108+
X<|.DEFINITE>
109109
110110
Declaring a class creates a new I<type object> which, by default, is installed into
111111
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
115115
refer to it later, such as to create class instances by calling the C<new>
116116
method.
117117
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:
121120
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!
128134
129135
=head1 State
130136

0 commit comments

Comments
 (0)