Class: Dicey::NumericDie
- Inherits:
-
AbstractDie
- Object
- AbstractDie
- Dicey::NumericDie
- Defined in:
- lib/dicey/numeric_die.rb
Overview
A die which only has numeric sides, with no shenanigans.
The only inherent difference in behavior compared to AbstractDie is that this class checks values for sides on initialization. However, other classes may reject AbstractDie even with all numeric sides.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from AbstractDie
Instance Method Summary collapse
-
#initialize(sides_list) ⇒ NumericDie
constructor
A new instance of NumericDie.
Methods inherited from AbstractDie
#==, #current, describe, #eql?, from_count, from_list, #hash, #next, rand, #roll, srand, #to_s
Constructor Details
#initialize(sides_list) ⇒ NumericDie
Returns a new instance of NumericDie.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dicey/numeric_die.rb', line 14 def initialize(sides_list) if Range === sides_list unless Integer === sides_list.begin && Integer === sides_list.end raise DiceyError, "`#{sides_list.inspect}` is not a valid range!" end else sides_list.each do |value| raise DiceyError, "`#{value.inspect}` is not a number!" unless Numeric === value end end super end |