Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a straightforward way to check if something is a mixin?

Tags:

mixins

raku

Raku mixins have two (or more) natures, combining several values in the same container, or values along with roles. However, there is not, as far as I can tell, a straightforward way to check for "mixinity" in a variable that has not been created by you.

This might be a trick

my $foo = 3 but Stringy;
say $foo.^name ~~ /\+/;# OUTPUT: «「+」␤»

But is there any other property I'm missing that would allow to look this up directly?

like image 820
jjmerelo Avatar asked Mar 31 '21 10:03

jjmerelo


1 Answers

I think you're missing the ^roles and ^parents meta-methods:

my $foo = 3 but Stringy;
dd $foo.^roles;   # (Stringy, Real, Numeric)
dd $foo.^parents; # (Int,)
like image 133
Elizabeth Mattijsen Avatar answered Oct 15 '22 18:10

Elizabeth Mattijsen