Class: Dice
- Inherits:
-
Array
- Object
- Array
- Dice
- Defined in:
- lib/game_dice/dice.rb
Overview
A Dice object represents a collection of individual Die objects. Defaults to two dice.
Instance Method Summary collapse
-
#initialize(amount = 2, sides = 6) ⇒ Dice
constructor
Dice collection defaults to 2d6.
-
#roll ⇒ Object
Roll all the dice.
- #to_s ⇒ Object
-
#total ⇒ Object
Check the current roll for all dice.
Constructor Details
Instance Method Details
#roll ⇒ Object
Roll all the dice
10 11 12 |
# File 'lib/game_dice/dice.rb', line 10 def roll self.inject(0) { |total, current| total += current.roll } end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/game_dice/dice.rb', line 19 def to_s "A collection of dice #{self.collect { |i| i.last_roll }}, total: #{total}." end |
#total ⇒ Object
Check the current roll for all dice
15 16 17 |
# File 'lib/game_dice/dice.rb', line 15 def total self.inject(0) { |total, current| total += current.last_roll } end |