Created
October 19, 2015 13:32
-
-
Save phamer/71b8b38e565bca363b81 to your computer and use it in GitHub Desktop.
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; | |
subset NonNegRat of Rat where * >= 0; | |
class Point { | |
has $.x is rw is required; | |
has $.y is rw is required; | |
} | |
class Dimension { | |
has NonNegRat $.x is rw is required; | |
has NonNegRat $.y is rw is required; | |
} | |
class Room { | |
has Dimension $.dim; | |
method new( $x, $y ) { | |
# what to do here? | |
# I want to create a new Room instance, with $.dim constructed with $x, $y as dimensions | |
} | |
method info() { | |
say "Hi, I'm a room of dimensions ", $.dim.x, " x ", $.dim.y; | |
} | |
} | |
# ignore $roomfile for now | |
sub MAIN( $roomfile ) | |
{ | |
# w/o method new() declaration, this works as intended | |
#my $room = Room.new( dim => Dimension.new( x => 400.0, y => 500.0 ) ); | |
#$room.info(); | |
my $room2 = Room.new( 4.0, 5.0 ); | |
$room2.info(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try :