Thread Hash to Class-Attributes (21 answers)
Opened by Kuerbis at 2016-01-06 09:57

Kuerbis
 2016-01-12 08:43
#183476 #183476
User since
2011-03-20
938 articles
BenutzerIn
[default_avatar]
Wenn das Attribute ein Array ist, dann müsste ich das gesondert behandeln:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env perl6
use v6;

class Term::Choose {
    has Str $.prompt is rw = 'Your Choice';
    has Int @.mark   is rw;

    method choose ( Array $orig_list, %opt? ) {
        for %opt.pairs {
            self."{.key}"() = .value;
        }
    }
}

my $n = Term::Choose.new();
$n.choose( [ 1 .. 10 ], { prompt => 'BBBBB', mark => [ 1 .. 4 ] } );

#Type check failed in assignment to @!mark; expected Int but got Array
#  in method choose at ... line 10
#  in block <unit> at ... line 16

View full thread Hash to Class-Attributes