Skip to content

Instantly share code, notes, and snippets.

@khalidelboray
Created May 28, 2020 06:15
Show Gist options
  • Save khalidelboray/654d5b380be2e987f44927152af1802f to your computer and use it in GitHub Desktop.
Save khalidelboray/654d5b380be2e987f44927152af1802f to your computer and use it in GitHub Desktop.
Raku issue
class TextInput {
has $.value is rw is default(2);
method value() is rw {
return Proxy.new:
FETCH => sub ($) { return $!value },
STORE => sub ($, $new) {
X::OutOfRange .new(
:range(0..50 ),
:got($new),
:what("Input Value")).throw if $new > 50;
$!value = $new * 5;
}
}
method inc-print {
$!value = $!value * 20;
say $!value
}
}
my $t = TextInput.new();
$t.value = 5;
put $t.value;
# running this method will work so it is not readonly ?
#$t.inc-print
@khalidelboray
Copy link
Author

return overrides is-rw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment