Perhaps I am using class incorrectly, but I set up a class, then change
some of the parameters in an instance of the class. Next I would like to
discover what the current state of the instance is.
However, I could find no specification of how to access multiple
attributes, as opposed to multiple uses of methods.
Assume, class A {has $.a; has $.b; method abc {say 'some'} }; my A $x
.=new(:a(5), :b(6));
Note that indirection is possible with class methods, using
$x."$methodname", but the same does not exist for attributes.
It is possible to get a list of attributes with $x.^attributes but how
then to turn that list into accessors?
I found the following works inside the class definition:
class B {has $.a; has $.b; method state {for self.^attributes { say
"\$x$_ = " ~ eval qq[ $_ ] } } };
my B $x .=new(:a(5), :b(66));
$x.state;
but that seems to be a bit of a hack. Also I have not found a nice way
to achieve the same outside the class definition
What have I not seen?
Regards,
Richard <finanalyst>