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

Re: augment again

Thread Previous
From:
Brandon Allbery
Date:
October 19, 2018 02:08
Subject:
Re: augment again
Message ID:
CAKFCL4U6DEocCnSWAv+1-Y9L8wArutVMOfG8E8pTMZg7j4hQzA@mail.gmail.com
pyanfar Z$ 6 'use MONKEY-TYPING; augment class Any {method hic { say "hoc"
}}; my @a = <a b c d>; @a.hic'
No such method 'hic' for invocant of type 'Array'. Did you mean 'hic'?
  in block <unit> at -e line 1

zsh: exit 1
pyanfar Z$ 6 'use MONKEY-TYPING; augment class Any {method hic { say "hoc"
}}; Array.^compose; my @a = <a b c d>; @a.hic'
hoc

Basically you have to re-compose any class you want to see the added
methods.

On Thu, Oct 18, 2018 at 9:53 PM Joseph Brenner <doomvox@gmail.com> wrote:

> I've got another question about aug--yes, I know--ment.
>
> I've got a module ides_of_augment.pm6:
>
>   use MONKEY-TYPING;
>   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
>   hic!
>   > 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")?
>


-- 
brandon s allbery kf8nh
allbery.b@gmail.com

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About