@@ -245,18 +245,17 @@ with my $o2 = $o1.clone {
245
245
}
246
246
247
247
# Hash and Array attribute modifications in clone appear in original as well:
248
- say $o1; # OUTPUT: «Foo.new(foo => 42, bar => ["Z", "Y"], baz => {:X("W"), :Z("Y")}, …»
249
- say $o2; # OUTPUT: «Foo.new(foo => 70, bar => ["Z", "Y"], baz => {:X("W"), :Z("Y")}, …»
248
+ say $o1;
249
+ # OUTPUT: «Foo.new(foo => 42, bar => ["Z", "Y"], baz => {:X("W"), :Z("Y")}, …»
250
+ say $o2;
251
+ # OUTPUT: «Foo.new(foo => 70, bar => ["Z", "Y"], baz => {:X("W"), :Z("Y")}, …»
250
252
$o1.boo.(); # OUTPUT: «Hi»
251
253
$o2.boo.(); # OUTPUT: «Bye»
252
254
= end code
253
255
254
256
To clone those, you could implement your own C < .clone > that clones the
255
257
appropriate attributes and passes the new values to C < Mu.clone > , for example,
256
- via L « C < nextwith > |/language/functions#sub_nextwith» . Alternatively,
257
- your own C < .clone > could clone self first
258
- (using C < self.Mu::clone > or L « C < callsame > |/language/functions#sub_callsame» )
259
- and then manipulate the clone as needed, before returning it.
258
+ via L « C < nextwith > |/language/functions#sub_nextwith» .
260
259
261
260
= begin code
262
261
class Bar {
@@ -266,7 +265,7 @@ class Bar {
266
265
method clone { nextwith :foo(@!foo.clone), :bar(%!bar.clone), |%_ }
267
266
}
268
267
269
- my $o1 = Bar.new;
268
+ my $o1 = Bar.new( :42quux ) ;
270
269
with my $o2 = $o1.clone {
271
270
.foo = <Z Y>;
272
271
.bar = <Z Y X W>;
0 commit comments