Created
December 29, 2016 22:01
-
-
Save dugword/d4e5b0dfbf02484df5802d49d4f59ba4 to your computer and use it in GitHub Desktop.
multi method new in Perl 6 Class Raw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
say "Testing classes"; | |
my class Foo { | |
has $.bar; | |
has $.baz; | |
multi method new (:$bar!, :$baz!) { | |
return self.bless(:$bar, :$baz); | |
} | |
multi method new (:$baz!) { | |
my $bar = 'bar'; | |
# my $baz = $baz | |
return self.bless(:$bar, :$baz); | |
} | |
multi method new (:$bar!) { | |
my $baz = 'baz'; | |
return self.bless(:$bar, :$baz); | |
} | |
multi method new { | |
my $bar = 'foo'; | |
my $baz = 'foo'; | |
return self.bless(:$bar, :$baz); | |
} | |
} | |
my $foo1 = Foo.new(); | |
my $foo2 = Foo.new(bar => 'puppies'); | |
my $foo3 = Foo.new(baz => 'kitties'); | |
my $foo4 = Foo.new(baz => 'ponies', bar => 'butterflies'); | |
dd $foo1; | |
dd $foo2; | |
dd $foo3; | |
dd $foo4; | |
## OUTPUT | |
# Testing classes | |
# Foo $foo1 = Foo.new(bar => "foo", baz => "foo") | |
# Foo $foo2 = Foo.new(bar => "puppies", baz => "baz") | |
# Foo $foo3 = Foo.new(bar => "bar", baz => "kitties") | |
# Foo $foo4 = Foo.new(bar => "butterflies", baz => "ponies") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment