Skip to content

Instantly share code, notes, and snippets.

@smls
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smls/7a005bcc3716e993ae09 to your computer and use it in GitHub Desktop.
Save smls/7a005bcc3716e993ae09 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl6
class A {
has $.int is rw;
has @.AoA is rw;
has @.AoH is rw;
has %.HoH is rw;
method copy {
self.new(
int => $.int,
AoA => @.AoA.deepmap(*.clone),
AoH => @.AoH.deepmap(*.clone),
HoH => %.HoH.deepmap(*.clone),
)
}
};
my $new = A.new(
int => 2,
AoA => [[2, 2], [2, 2]],
AoH => [{a => 2}, {a => 2}],
HoH => {a => {a => 2}},
);
my $copy = $new.copy;
$new.int = 4;
$new.AoA[0][0] = 4;
$new.AoH[0]<a> = 4;
$new.HoH<a><a> = 4;
dd $new, $copy
$new = A.new(int => 4, AoA => [[4, 2], [2, 2]]<>, AoH => [{:a(4)}, {:a(2)}]<>, HoH => {:a({:a(4)})}<>)
$copy = A.new(int => 2, AoA => [[2, 2], [2, 2]]<>, AoH => [{:a(2)}, {:a(2)}]<>, HoH => {:a({:a(2)})}<>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment