Camelia
Prev: Simple Point class

Read/write attributes and accessors

Setting the "rw" trait on the attribute will also generate a read-write accessor that is an lvalue so you assign to it.
examples/classes/point_02.p6
use v6;

class Point {
    has $.x is rw;
    has $.y is rw;
    
};

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

say $a.x;   # 23

$a.x = 10;

say $a.x;   # 10



Prev: Simple Point class

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: