Class: Randsum::Die
- Inherits:
-
Object
- Object
- Randsum::Die
- Defined in:
- lib/randsum/die.rb
Constant Summary collapse
- ZERO_INDEX_FIXER =
1
Instance Attribute Summary collapse
-
#randomizer ⇒ Object
Returns the value of attribute randomizer.
-
#sides ⇒ Object
Returns the value of attribute sides.
Instance Method Summary collapse
-
#initialize(sides, randomizer: SecureRandom) ⇒ Die
constructor
A new instance of Die.
- #roll(quantity = 1) ⇒ Object
- #simple_roll ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(sides, randomizer: SecureRandom) ⇒ Die
Returns a new instance of Die.
8 9 10 11 |
# File 'lib/randsum/die.rb', line 8 def initialize(sides, randomizer: SecureRandom) @sides = sides @randomizer = randomizer end |
Instance Attribute Details
#randomizer ⇒ Object
Returns the value of attribute randomizer.
6 7 8 |
# File 'lib/randsum/die.rb', line 6 def randomizer @randomizer end |
#sides ⇒ Object
Returns the value of attribute sides.
6 7 8 |
# File 'lib/randsum/die.rb', line 6 def sides @sides end |
Instance Method Details
#roll(quantity = 1) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/randsum/die.rb', line 13 def roll(quantity = 1) Randsum::Roll.new( quantity: quantity, die: self ) end |
#simple_roll ⇒ Object
24 25 26 |
# File 'lib/randsum/die.rb', line 24 def simple_roll randomizer.random_number(sides).to_i + ZERO_INDEX_FIXER end |
#to_s ⇒ Object
20 21 22 |
# File 'lib/randsum/die.rb', line 20 def to_s "d#{sides}" end |