Skip to content

Commit

Permalink
Add example for Code.line with automatic accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
codesections authored and JJ committed Aug 31, 2020
1 parent e539502 commit 4b94178
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions doc/Type/Code.pod6
Expand Up @@ -184,16 +184,33 @@ Defined as
method line(Code:D: --> Int:D)
Returns the line number in the source code at which the code object's
declaration begins. If the code object was generated automatically
(and thus I<not> declared in the source code), then C<line> returns
the line on which the enclosing scope's declaration begins. For
example, when called on an L<automatically generated accessor
method|/language/objects#Attributes> produced by
the C<has $.name> syntax, C<line> returns the line on which the
method's class's declaration begins.
declaration begins.
say &infix:<+>.line;
If the code object was generated automatically (and thus I<not>
declared in the source code), then C<line> returns the line on which
the enclosing scope's declaration begins. For example, when called on
an L<automatically generated accessor method|
/language/objects#Attributes> produced by the C<has $.name>
syntax, C<line> returns the line on which the method's class's
declaration begins.
For example, if you have the following source file:
class Food { # Line 1
has $.ingredients; # Line 2
# Line 3
method eat {}; # Line 4
} # Line 5
Then the C<line> method would give you the following output:
=begin code :preamble<class Food { has $.ingredients; method eat {};}>
say Food.^lookup('eat').line; # OUTPUT: «4␤»
say Food.^lookup('ingredients').line; # OUTPUT: «1␤»
=end code
=head2 method is-implementation-detail
method is-implementation-detail(--> False)
Expand Down

0 comments on commit 4b94178

Please sign in to comment.