On 05/25/2014 09:50 AM, Kamil Kułaga wrote:
> Hi,
>
> My question is about passing parameters to .new method that do not
> correspond to any field in class. This example;
>
> use v6;
>
> class PersonalId{
>     has Int $.number;
>     has Str $.full_name;
> }
>
> my Hash $p; #just because i'm scared of pair conversions
> $p{"number"} = 13123123123;
> $p{"full_name"} = "John Doe";
> $p{"age"}=64;
> $p{"shoesize"}=44;
>
> say PersonalId.new(|%($p)).perl;
> # PersonalId.new(number => 13123123123, full_name => "John Doe")
>
> Works perfectly fine but I don't know whether I can rely on that. S12
> speaks only about type objects: (It is allowed to pass type objects
> that don't correspond to any parent class.)

Hello Kamil,

methods (such as the automatically generated new method) take an
implicit *%_ parameter, which will slurp up the excess named parameters.
This is called "interface consistency". You can find more about it in
the synopsis here:

http://perlcabal.org/syn/S12.html#Interface_Consistency

Hope to help!
  - Timo


PS: Due to a misbehaving mail client extension, his mail didn't end up
reaching the mailing list when I sent it; sorry!

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to