Skip to content

Instantly share code, notes, and snippets.

@rightfold
Created January 25, 2015 20:31
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 rightfold/fefad5f66e7654e1a0e5 to your computer and use it in GitHub Desktop.
Save rightfold/fefad5f66e7654e1a0e5 to your computer and use it in GitHub Desktop.
multi trait_mod:<is>(Mu $class, :$record!) {
$class.^add_method('WHICH', anon method WHICH {
my @attributes = $class.^attributes;
my @xs = map({ .get_value(self).WHICH }, @attributes);
Bag.new(@xs).WHICH;
});
};
class Person is record {
has $.name;
has $.age;
has @.pets;
}
my $person-a = Person.new(:name<Kristien>, :age(20), :pets<Goldfish Cat>);
say $person-a.WHICH;
my $person-b = Person.new(:name<Kristien>, :age(20), :pets<Goldfish Cat>);
say $person-b.WHICH;
my $person-c = Person.new(:name<vendethiel>, :age(20), :pets<Goldfish Cat>);
say $person-c.WHICH;
my @people = $person-a, $person-b, $person-c;
map { say $^a.perl, ' === ', $^b.perl, ' = ', ($^a === $^b); }, (@people X @people);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment