This is similar to, but not quite the same as another of my questions: Content checking some, not all, class attributes
I am writing a test to verify the effect of processing on a object. But I can't work out how to get the value of a known set of the object's attributes but test with the same code. Something like the following (which does not work):
class A { has $.a, has $.b, has $.c };
my A $v .=new(:1a, :2b);
for <a b> { ok $v.{$_} > 0 }; # this does not work, but illustrates the intent.
If instead of an object I had used a Hash, then it is easy to get values from the Hash knowing the keys.
At the moment all I can think of is to test each attribute:
ok $v.a > 0;
ok $v.b > 0;
In addition, I don't want to look at ALL the attributes of the object, which is what .^attributes gives me, only some of them.
for <a b> { ok $v."$_"() > 0 };. Would that solve your problem? You could also implement theAssociativerole to make your sample work as-is. - Tyil