Hi, On 25.03.2015 13:44, Tom Browder wrote: > Given a class like: > > our %attrs = (age=>1,wgt=>2); > class foo { has $.age = rw;}
should be 'has $.age is rw'. The "is" indicates a trait (not an assignment). > method a { > for %attrs.kv -> $k, $v { > my $aval = self."$k"(); # supposed to work for a method name Etiher method a needs to be inside class foo, or it needs to be a subroutine, and refer to foo instead of self here. A method outside a class doesn't ususally make sense, which is why you get this message: Other potential difficulties: Useless declaration of a has-scoped method in mainline (did you mean 'my method a'?) > say "attr { $k } has value '{ $aval }'"; > } > } > > Question: > > 1. How can I indirectly refer to the attributes in a method? The > above doesn't work (with or without the '()'). the indirect method call syntax is the right approach, you just got too many other details wrong to make it work. Cheers, Moritz