Class: Dicey::RegularDie
- Inherits:
-
NumericDie
- Object
- AbstractDie
- NumericDie
- Dicey::RegularDie
- Defined in:
- lib/dicey/regular_die.rb
Overview
Regular die, which has N sides with numbers from 1 to N.
As a subclass of NumericDie, enjoys its treatment.
Instance Attribute Summary
Attributes inherited from AbstractDie
Instance Method Summary collapse
-
#initialize(max) ⇒ RegularDie
constructor
A new instance of RegularDie.
-
#to_s ⇒ String
Return a string representing the die.
Methods inherited from AbstractDie
#==, #current, describe, #eql?, from_count, from_list, #hash, #next, rand, #roll, srand
Constructor Details
#initialize(max) ⇒ RegularDie
Returns a new instance of RegularDie.
11 12 13 14 15 16 17 |
# File 'lib/dicey/regular_die.rb', line 11 def initialize(max) unless Integer === max && max.positive? raise DiceyError, "regular dice can contain only positive integers, #{max.inspect} is not" end super((1..max)) end |
Instance Method Details
#to_s ⇒ String
Return a string representing the die.
Regular dice are represented with a “D” followed by the number of sides.
24 25 26 |
# File 'lib/dicey/regular_die.rb', line 24 def to_s "D#{sides_num}" end |