Class: Stattr::DiceRoll
- Inherits:
-
Object
- Object
- Stattr::DiceRoll
- Defined in:
- lib/stattr.rb
Overview
Represents a single instance of the result of a dice roll
Instance Attribute Summary collapse
-
#count ⇒ Object
The number of die being rolled.
-
#sides ⇒ Object
The number of sides the dice in this roll have.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(sides = Game.dice_sides, count = Game.dice_num) ⇒ Object
constructor
New instance of DiceRoll.
-
#roll ⇒ Integer
Adds the rolls from rolls together.
-
#rolls ⇒ Integer
From 1 to count, that many [sides] sided die.
Constructor Details
#initialize(sides = Game.dice_sides, count = Game.dice_num) ⇒ Object
New instance of DiceRoll.
def initialize(sides=DICE_SIDES, count=1)
60 61 62 63 |
# File 'lib/stattr.rb', line 60 def initialize(sides=Game.dice_sides, count=Game.dice_num) @sides = sides @count = count end |
Instance Attribute Details
#count ⇒ Object
The number of die being rolled.
51 |
# File 'lib/stattr.rb', line 51 attr_accessor :sides, :count |
#sides ⇒ Object
The number of sides the dice in this roll have.
51 52 53 |
# File 'lib/stattr.rb', line 51 def sides @sides end |
Class Method Details
.new_roll(sides = Game.dice_sides, count = Game.dice_num) ⇒ Object
Roll a new die.
71 72 73 74 |
# File 'lib/stattr.rb', line 71 def self.new_roll(sides = Game.dice_sides, count=Game.dice_num) # make a new dice object, then roll it. new(sides, count).roll end |
Instance Method Details
#roll ⇒ Integer
Adds the rolls from rolls together.
88 89 90 |
# File 'lib/stattr.rb', line 88 def roll rolls.inject(0) { |total, d| total += d } end |
#rolls ⇒ Integer
From 1 to count, that many [sides] sided die.
80 81 82 |
# File 'lib/stattr.rb', line 80 def rolls (1..count).map { |d| rand(sides) + 1 } end |