Skip to content

Instantly share code, notes, and snippets.

@uasi
Created January 24, 2010 18:07
Show Gist options
  • Save uasi/285344 to your computer and use it in GitHub Desktop.
Save uasi/285344 to your computer and use it in GitHub Desktop.
class A {
has ($.foo, $.bar, $.baz, $.qux, $.blahblahblah);
# Is there a way to define a constructor that takes positional arguments
# and initializes attributes of the same name
# (I assume the definition looks like this)
#
method NEW ($!foo, $!bar, $!baz, $!qux, $!blahblahblah) { }
# ... instead of repeating variables to bless?
#
method new ($foo, $bar, $baz, $qux, $blahblahblah) {
self.bless(*, :$foo, :$bar, :$baz, :$qux, :$blahblahblah); # not so DRY, is it?
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment