Skip to content

Commit 6ed2497

Browse files
dumarchieJJ
authored andcommitted
Improve documentation of Hash.push
* correct signature * sub push throws if it receives an unexpected named argument
1 parent da246d0 commit 6ed2497

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

doc/Type/Hash.pod6

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,9 @@ its return value will be used instead of the original C<@list>'s item:
313313
314314
Defined as:
315315
316-
multi method push(Hash:D: *@new)
316+
method push(Hash:D: +new)
317317
318-
Adds the C<@new> elements to the hash with the same semantics as hash
318+
Adds the C<new> elements to the hash with the same semantics as hash
319319
assignment, but with three exceptions:
320320
321321
=item The hash isn't emptied first, i.e. old pairs are not deleted.
@@ -336,15 +336,13 @@ Example:
336336
%h.push('c' => 4); # a => [1,1,1,1,1], b => 3, c => 4
337337
push %h, 'd' => 5; # a => [1,1,1,1,1], b => 3, c => 4, d => 5
338338
339-
Please note that C<Pair>s or
340-
L<colon pairs|/language/glossary#index-entry-Colon_Pair> as arguments to push
341-
will be treated as extra named arguments and as such wont end up the C<Hash>.
342-
The same applies to the sub C<push>.
339+
Please note that literal pairs in the argument list may be interpreted as
340+
L<named arguments|/type/Capture> and as such won't end up in the C<Hash>.
341+
The C<push> subroutine will throw if it receives a named argument.
343342
344343
my %h .= push(e => 6);
345-
push %h, f => 7;
346-
say %h.raku;
347-
# OUTPUT: «{}␤»
344+
try push %h, f => 7;
345+
say %h.raku; # OUTPUT: «{}␤»
348346
349347
Also note that push can be used as a replacement for assignment during hash
350348
initialization very useful ways. Take for instance the case of an inverted

0 commit comments

Comments
 (0)