Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Clairfy type object/instance .defined thing
Toss .defined and use better methods
  • Loading branch information
zoffixznet committed Dec 12, 2016
1 parent 88240a9 commit a516adf
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions doc/Language/classtut.pod6
Expand Up @@ -104,8 +104,8 @@ through the C<has> keyword, and behaviors introduced through the C<method>
keyword.
X<|type object>
X<|defined>
X<|.defined>
X<|DEFINITE>
X<|.DEFINITE>
Declaring a class creates a new I<type object> which, by default, is installed into
the current package (just like a variable declared with C<our> scope). This
Expand All @@ -115,16 +115,22 @@ classes. The example above uses the class name C<Task> so that other code can
refer to it later, such as to create class instances by calling the C<new>
method.
Type objects are I<undefined>, in the sense that they return C<False> if you
call the C<.defined> method on them. You can use this method to find out if
a given object is a type object or not:
You can use C<.DEFINITE> method to find out if what you have is an instance
or a type object:
my $obj = Int;
if $obj.defined {
say "Ordinary, user-defined object";
} else {
say "Type object";
}
say Int.DEFINITE; # False (type object)
say 426.DEFINITE; # True (instance)
class Foo {};
say Foo.DEFINITE; # False (type object)
say Foo.new.DEFINITE; # True (instance)
You can also use type smileys to only accept instances or type objects:
multi foo (Int:U) { "It's a type object!" }
multi foo (Int:D) { "It's an instance!" }
say foo Int; # It's a type object!
say foo 42; # It's an instance!
=head1 State
Expand Down

0 comments on commit a516adf

Please sign in to comment.