RosettaCodeData/Task/Delegates/Perl-6/delegates.pl6
Ingy döt Net d066446780 langs a-z
2013-04-10 22:43:41 -07:00

28 lines
429 B
Raku

class Non-Delegate { }
class Delegate {
method thing {
return "delegate implementation"
}
}
class Delegator {
has $.delegate is rw;
method operation {
$.delegate.^can( 'thing' ) ?? $.delegate.thing
!! "default implementation"
}
}
my Delegator $d .= new;
say "empty: "~$d.operation;
$d.delegate = Non-Delegate.new;
say "Non-Delegate: "~$d.operation;
$d.delegate = Delegate.new;
say "Delegate: "~$d.operation;