Re: Perl 6 Class Questions

2010-09-18 Thread Moritz Lenz
yary wrote: > A "roll" method was just added, though I don't think its implemented > yet. It is. .roll is what .pick(:replace) used to be, so it was "just" a matter of splitting up the existing methods $ ./perl6 -e 'say ~(1..6).roll(10)' 3 1 5 6 5 6 5 4 2 5 (works in Rakudo HEAD, and will work i

Re: Perl 6 Class Questions

2010-09-18 Thread yary
return round 1 + rand * $!sides; Might be good to refer to http://perlcabal.org/syn/S32/Containers.html for a more idiomatic way of picking an integer, eg "return (1..$sides).pick" A "roll" method was just added, though I don't think its implemented yet. If you're only getting one value then

Re: Perl 6 Class Questions

2010-09-18 Thread Moritz Lenz
Phil Crow wrote: > class Die; > > has Int $!sides; > > method new( Int $sides = 6 ) { > return self.bless( *, :$sides ); > } > > method roll() returns Int { > return round 1 + rand * $!sides; > } Just as a side note, this is could be easier written as