develooper Front page | perl.perl6.users | Postings from October 2018

augment again

Thread Next
Joseph Brenner
October 19, 2018 01:52
augment again
Message ID:
I've got another question about aug--yes, I know--ment.

I've got a module ides_of_augment.pm6:

  augment class Any {
      method hiccup {
          say "hic!";

I would've thought it could be used in the repl like this:

  perl6 -Mides_of_augment

  > (Any).hiccup
  > my @a=< a b c d >;
  [a b c d]
  > @a.hiccup
  No such method 'hiccup' for invocant of type 'Array'. Did you mean 'hiccup'?
    in block <unit> at <unknown file> line 1

As you can see, it kind-of augments the Any class, but evidently
does it too late to (completely) change an instance of Array.

I tried a few things like "BEGIN augment" or "INIT augment"
without any luck.

Any suggestions (besides "don't do it")?

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About