Created
August 3, 2015 20:55
-
-
Save ronaldxs/e0a325c9e3bc716cf7f7 to your computer and use it in GitHub Desktop.
attribute mutator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A { | |
has $.a; | |
method a is rw { | |
Proxy.new( | |
FETCH => -> $self { $!a }, | |
STORE => -> $self, Int $v { $!a = $v * 2 } | |
); | |
} | |
} | |
my $o = A.new; | |
$o.a = 123; | |
say $o.a; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment