Re: oop pre salt question

[email protected] (Elizabeth Mattijsen)
Newsgroups perl.perl6.users
Message-ID <[email protected]>
class Fruit {
      has Str  $.location is rw = "Cucamonga";
      has UInt $.apples   is rw = 400;
      has UInt $.oranges  is rw = 200;
      has UInt $.bananas  is rw = 50;
``}

> On 16 Dec 2024, at 10:49, ToddAndMargo via perl6-users <[email protected]> wrote:
> 
> Hi All,
> 
> In the following;
> 
>   class Fruit {
>       has Str  $.location is rw;
>       has UInt $.apples   is rw;
>       has UInt $.oranges  is rw;
>       has UInt $.bananas  is rw;
>   }
> 
>   #  Pre-salted:
>         my $FruitStand = Fruit.new( location => "Cucamonga",
>                                     apples   => 400,
>                                     oranges  => 200,
>                                     bananas  => 50  );
> 
> Is there a way in the class declaration that I can
> set the default values such that the "my" creation
> of the variable already has the default values in it?
> 
> Many thanks,
> -T
> 
> 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.