Sha256: e1c8ce9037521a7a1bbb4fb18ee2b229582d1a49a840a3da21358713151db07f
Contents?: true
Size: 548 Bytes
Versions: 1
Compression:
Stored size: 548 Bytes
Contents
class DMTool::Die attr_reader :sides, :explodes, :history def initialize(sides: 6, explodes: false) raise ArgumentError.new("Invalid sides: #{sides}") unless sides.is_a?(Fixnum) && sides > 1 @sides = sides @explodes = explodes @history = [] end def value @history.last end def roll result = rand_roll result += rand_roll while explodes? && result % sides == 0 history.push result result end alias explodes? explodes alias roll! roll private def rand_roll rand(1..sides) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dmtool-0.0.1 | lib/dmtool/die.rb |