Class: Dicey::RegularDie

Inherits:
NumericDie show all
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

#sides_list, #sides_num

Instance Method Summary collapse

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.

Parameters:

  • max (Integer)

    maximum side / number of sides



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_sString

Return a string representing the die.

Regular dice are represented with a “D” followed by the number of sides.

Returns:

  • (String)


24
25
26
# File 'lib/dicey/regular_die.rb', line 24

def to_s
  "D#{sides_num}"
end