Skip to content

Instantly share code, notes, and snippets.

@khalidelboray
Created May 31, 2020 12:53
Show Gist options
  • Save khalidelboray/cb2791b3df2dd501786c6734c65acde7 to your computer and use it in GitHub Desktop.
Save khalidelboray/cb2791b3df2dd501786c6734c65acde7 to your computer and use it in GitHub Desktop.
Raku `.clone` note
class Tweaked {
has $.a;
has $.b;
has $.mod;
submethod TWEAK() {
$!mod = "Modified : " ~ $!mod
}
method clone() {
my $mod = %_<mod>:delete;
nextwith :mod( "Modified : " ~ $mod ) , |%_;
}
}
Tweaked.new(:a(1),:b(2),:mod("So ?")).raku.put;
# OUTPUT : Tweaked.new(a => 1, b => 2, mod => "Modified : So ?")
Tweaked.new(:a(1),:b(2),:mod("So ?")).clone(:mod("ALSO THIS")).raku.put;
# OUTPUT : Tweaked.new(a => 1, b => 2, mod => "Modified : ALSO THIS")
class Tweaked {
has $.a;
has $.b;
has $.mod;
submethod TWEAK() {
$!mod = "Modified : " ~ $!mod
}
}
Tweaked.new(:a(1),:b(2),:mod("So ?")).raku.put;
# OUTPUT : Tweaked.new(a => 1, b => 2, mod => "Modified : So ?")
Tweaked.new(:a(1),:b(2),:mod("So ?")).clone(:mod("NOT THIS")).raku.put;
# OUTPUT : Tweaked.new(a => 1, b => 2, mod => "NOT THIS")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment