๐Ÿ“˜ Method postfix operator .= in Perl 6

๐Ÿ“˜ Method postfix operator .= in Raku

N. B. Perl 6 has been renamed to Raku. Click to read more.

.=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)ย 

say $o.WHAT;ย  # (D)

Leave a Reply

Your email address will not be published. Required fields are marked *

Retype the CAPTCHA code from the image
Change the CAPTCHA codeSpeak the CAPTCHA code