Camelia
Prev: Read/write attributes and accessors

Class Methods

The "method" keyword can be used to create methods for the class.
examples/classes/point_03.p6
use v6;

class Point {
    has $.x is rw;
    has $.y is rw;
    
    method reset {
        $.x = 0;
        $.y = 0;
    }
};

my $a = Point.new(x => 23, y => 42);

say $a.x;  # 23

$a.reset;

say $a.x;  # 0

Prev: Read/write attributes and accessors

Table of Contents

Comments

In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
comments powered by Disqus

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: