📘 Method postfix operator .= in Perl 6

.=method is a mutating call of the method on an object. The call $x.=method does the same as the more verbose assignment $x = $x.method.

In the following example, the $o container initially holds an object of the C class, but after $o.=m(), the value will be replaced with an instance of the D class.

class D { } 

class C {
    method m() {
        return D.new;
    }
}

my $o = C.new;
say $o.WHAT;  # (C) 

$o.=m();
say $o.WHAT;  # (D)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s