How do you add a method to an existing class in Perl 6?

后端 未结 4 1874
太阳男子
太阳男子 2021-02-19 04:40

The Int class has a method is_prime, so I figured, just for giggles, I\'d like to add some other methods to Int for some of my hobby projects that do n

4条回答
  •  执念已碎
    2021-02-19 05:26

    There's another interesting way to do this if you need it only for some instances of a class. You can decorate an object with a role:

     my $decorated = $object but role { ... }
    

提交回复
热议问题