Skip to content

Instantly share code, notes, and snippets.

@Juerd
Created July 20, 2017 19:21
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 Juerd/b26ab3fbb704aa9812f4fc1b9ba429ad to your computer and use it in GitHub Desktop.
Save Juerd/b26ab3fbb704aa9812f4fc1b9ba429ad to your computer and use it in GitHub Desktop.
class Person is Entity does Location { }
class Place is Entity does Location { }
class Thing is Entity does Lendable { }
class Container is Entity does Lendable does Location { }
...
class Command::info is Command::Unary {
sub show-contents(Entity $entity where Location) {
my Entity @items = Entity.all-entities.grep(Lendable)
.grep({ .location && .location.id.lc eq $entity.id.lc });
put "$entity has { +@items } {
@items == 0 ?? 'items.' !! @items == 1 ?? 'item:' !! 'items:' }";
put yellow("* "), $_ for @items;
}
sub show-location(Entity $entity where Lendable) {
my $location = $entity.location;
without $location {
put "I don't know where $entity is.";
return;
}
put "$entity is currently at $location.";
Command::info.execute: $location if $location ~~ Lendable;
}
method execute(Entity $entity) {
show-contents $entity if $entity ~~ Location;
show-location $entity if $entity ~~ Lendable;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment