From 9be38b012949522590c57b60c6f16934f214f24f Mon Sep 17 00:00:00 2001 From: librasteve <40125330+librasteve@users.noreply.github.com> Date: Thu, 4 Jul 2024 13:04:25 +0100 Subject: [PATCH] Add simple use example --- doc/Language/101-basics.rakudoc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/doc/Language/101-basics.rakudoc b/doc/Language/101-basics.rakudoc index 2352ce52d..a8c1ee0df 100644 --- a/doc/Language/101-basics.rakudoc +++ b/doc/Language/101-basics.rakudoc @@ -461,6 +461,34 @@ say "we have @flavors.sort.join(', ')"; # OUTPUT: «we have peach, vanilla␤» =end code +=head1 Calling a raku method from another file + +To call a raku subroutine from another file, the convention is to have a minimal +raku module or class file. + +=begin code +# MyClass.rakumod +class C { + has $.x; +} +=end code + +Then your script can use this file. + +=begin code +# myscript.raku +use MyClass; + +my $instance = C.new(x=>42); +say $instance.x; +=end code + +The C<-I.> directive tells the raku interpreter to look in directory C<.>. + +=begin code +> raku -I. myscript.raku +=end code + =head1 Exercises B<1.> The input format of the example program is redundant: the first line