Class: Dicey::NumericDie

Inherits:
AbstractDie show all
Defined in:
lib/dicey/numeric_die.rb

Overview

A die which only has numeric sides, with no shenanigans.

Direct Known Subclasses

RegularDie

Instance Attribute Summary

Attributes inherited from AbstractDie

#sides_list, #sides_num

Instance Method Summary collapse

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.

Raises:

  • (DiceyError)

    if sides_list contains non-numerical values or is empty



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dicey/numeric_die.rb', line 10

def initialize(sides_list)
  if Range === sides_list
    unless Numeric === sides_list.begin && Numeric === sides_list.end
      raise DiceyError, "`#{sides_list.inspect}` is not a numerical range!"
    end
  else
    sides_list.each do |value|
      raise DiceyError, "`#{value.inspect}` is not a number!" unless Numeric === value
    end
  end

  super
end