Created
May 31, 2020 12:53
-
-
Save khalidelboray/cb2791b3df2dd501786c6734c65acde7 to your computer and use it in GitHub Desktop.
Raku `.clone` note
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 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") |
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 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