@@ -344,11 +344,11 @@ say $p.perl;
344
344
# OUTPUT: «Point-with-ID.new(ID => "*1-2", x => 1, y => 2)»
345
345
= end code
346
346
347
- In this code, C < bless > called within C < Point.new > is eventually calling C < BUILD >
348
- with the same parameters. We have to create a convoluted way of using the
349
- C < $.ID > attribute using the meta-object protocol so that we can instantiate it
350
- and thus serve that C < new > constructor, which can be called on C < Point-with-ID >
351
- since it is a subclass.
347
+ In this code, C < bless > , called within C < Point.new > , is eventually calling
348
+ C < BUILD > with the same parameters. We have to create a convoluted way of using
349
+ the C < $.ID > attribute using the meta-object protocol so that we can instantiate
350
+ it and thus serve that C < new > constructor, which can be called on
351
+ C < Point-with-ID > since it is a subclass.
352
352
353
353
We might have to use something similar if we want to instantiate superclasses.
354
354
C < bless > will help us with that, since it is calling across all the hierarchy:
@@ -373,20 +373,20 @@ class Str-with-ID is Str {
373
373
374
374
say Str-with-ID.new("1.1,2e2").ID; # OUTPUT: «0»
375
375
my $ided-str = Str-with-ID.new("3,4");
376
- say "$ided-str, {$ided-str.^name}, {$ided-str.ID}"; # OUTPUT: «3,4, Str-with-ID, 1»
376
+ say "$ided-str, {$ided-str.^name}, {$ided-str.ID}";
377
+ # OUTPUT: «3,4, Str-with-ID, 1»
377
378
= end code
378
379
379
- We are *enriching* C < Str > with an auto-incrementing ID. We create a C < new > since
380
- we want to initialize it with a string and, besides, we need to instantiate the
381
- superclass. We do so using C < bless > from within C < new > . C < bless > is going to
382
- call C < Str.BUILD > . It will *capture* the value it's
383
- looking for, the pair C < value = > $str> and initialize itself. But we have to
384
- initialize also the properties of the subclass, which is why within C < BUILD > we
385
- use the previously explained method to initialize C < $.ID > with the value that is
386
- in the C < %args > variable. As shown in the output, the objects will be correctly
387
- initialized with its ID, and will correctly behave as C < Str > , converting
388
- themselves in just the string in the C < say > statement, and including the C < ID >
389
- property as required.
380
+ We are I < enriching > C < Str > with an auto-incrementing ID. We create a C < new >
381
+ since we want to initialize it with a string and, besides, we need to
382
+ instantiate the superclass. We do so using C < bless > from within C < new > . C < bless >
383
+ is going to call C < Str.BUILD > . It will *capture* the value it's looking for, the
384
+ pair C < value = > $str> and initialize itself. But we have to initialize also the
385
+ properties of the subclass, which is why within C < BUILD > we use the previously
386
+ explained method to initialize C < $.ID > with the value that is in the C < %args >
387
+ variable. As shown in the output, the objects will be correctly initialized with
388
+ its ID, and will correctly behave as C < Str > , converting themselves in just the
389
+ string in the C < say > statement, and including the C < ID > property as required.
390
390
391
391
For more details see
392
392
L < the documentation on object construction|/language/objects#Object_Construction > .
@@ -457,9 +457,9 @@ mechanism when no direct candidate is available to dispatch to.
457
457
458
458
multi method WHICH(--> ObjAt:D)
459
459
460
- Returns an object of type L < ObjAt|/type/ObjAt > which uniquely identifies the object.
461
- Value types override this method which makes sure that two equivalent objects
462
- return the same return value from C < WHICH > .
460
+ Returns an object of type L < ObjAt|/type/ObjAt > which uniquely identifies the
461
+ object. Value types override this method which makes sure that two equivalent
462
+ objects return the same return value from C < WHICH > .
463
463
464
464
say 42.WHICH eq 42.WHICH; # OUTPUT: «True»
465
465
0 commit comments