Skip to content

Instantly share code, notes, and snippets.

@skrisna
Created October 18, 2019 01:25
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 skrisna/57c2e15beed8071faf82094253faeb10 to your computer and use it in GitHub Desktop.
Save skrisna/57c2e15beed8071faf82094253faeb10 to your computer and use it in GitHub Desktop.
Inheritance in Perl 6
class Animalia {
method full-name {
self.^name
}
}
class Arthropodia is Animalia {
method full-name {
callsame() ~ ', ' ~ self.^name
}
}
class Insecta is Arthropodia {
method full-name {
callsame() ~ ', ' ~ self.^name
}
}
class Lepidoptera is Insecta {
method full-name {
callsame() ~ ', ' ~ self.^name
}
}
class Nymphalidae is Lepidoptera {
method full-name {
callsame() ~ ', ' ~ self.^name
}
}
class Hamadryas is Nymphalidae {
method full-name {
put "{self.^name} is {callsame}"
}
}
my $h = Hamadryas.new;
$h.full-name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment