Why do I get different results?
class Car {
has $.wheels;
}
my $my_car = Car.new( wheels => 4 );
say $my_car ; # Car.new(wheels => 4)
say "$my_car"; # Car<94582644384824>
put $my_car ; # Car<94582644384824>
I suppose that in the 2nd and 3rd cases $my_car is stringified, but what does the result mean?
The say command calls .gist on its argument. The put command calls .Str on its argument. And this also happens when you interpolate your object.
The default gist method looks at the public attributes of an object, and creates a string from that.
You can control how your object gets stringified by supplying your own Str method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With