Created
October 19, 2015 21:21
-
-
Save phamer/a265d76ce94f7ea91e28 to your computer and use it in GitHub Desktop.
array as attribute
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 | |
use v6; | |
class Point { | |
has $.x is rw is required; | |
has $.y is rw is required; | |
method Str { "($.x,$.y)" } | |
} | |
class Line { | |
has Point $.point-start is rw is required; | |
has Point $.point-end is rw is required; | |
method Str { "$.point-start -- $.point-end" } | |
} | |
class Room { | |
has Line @!walls; | |
method read( ) { | |
my $l = Line.new( point-start => Point.new( x => 3, y => 4 ), point-end => Point.new( x => 5, y => 6 ) ); | |
# fails with | |
# Cannot look up attributes in a type object | |
# in method read at ./array-member.p6:34 | |
# in sub MAIN at ./array-member.p6:38 | |
# in block <unit> at ./array-member.p6:38 | |
say ">> new line $l"; | |
push @!walls, $l; | |
} | |
} | |
sub MAIN( ) | |
{ | |
my $room = Room.read(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment