Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogbert17/206507725af16451cd100033d5df0f91 to your computer and use it in GitHub Desktop.
Save dogbert17/206507725af16451cd100033d5df0f91 to your computer and use it in GitHub Desktop.
Feeble attempt to document method 'default' in class Hash
=head2 method default
Defined as:
method default returns ??? # what should be written here
Usage:
Hash.default
Returns the default value of the invocant, i.e. the value which is returned
when a non existing key is used to access an element in the C<Hash>.
Unless the C<Hash> is declared as having a default value by using the
L<is default|/routine/is default> trait the method returns the type object C<(Any)>.
my %h1 = 'apples' => 3, 'oranges' => 7;
say %h1.default; # (Any)
say %h1{'bananas'}; # (Any)
my %h2 is default(1) = 'apples' => 3, 'oranges' => 7;
say %h2.default; # 1
say %h2{'apples'} + %h2{'bananas'}; # 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment