class Rudil::Die
Public Class Methods
new(sides=6)
click to toggle source
# File lib/rudil/die.rb, line 3 def initialize sides=6 unless sides >= 1 and sides <= 120 raise ArgumentError # "120 sides should be enough for anybody." # Such a die would be an Hexakis Icosahedron, and I challenge # anyone to build it. # The biggest manufactured die to date has 100 sides and is # trademarked as Zocchihedron. It isn't a polyhedron anymore # but rather a ball with flattened planes (think golfball). else @sides = sides end end
Public Instance Methods
throw(times=1)
click to toggle source
# File lib/rudil/die.rb, line 17 def throw times=1 if times <= 0 raise ArgumentError end Array.new(times).fill { throw_once } end
throw_once()
click to toggle source
# File lib/rudil/die.rb, line 24 def throw_once # the part where randomness happens has it's own method # to simplify unit-testing by permitting it to be stubbed. rand(@sides)+1 end