Module: ParaDice::Die Abstract

Included in:
Faces::Arrayed, NumberedDie, StringDie
Defined in:
lib/para_dice/die.rb

Overview

This module is abstract.

A module meant to be the basis of a custom Die object with behaviour included from this die.

Constant Summary collapse

ERROR_MSG =
': Must be implemented in your Die class or included in a faces module.'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionString

Returns default ”.

Returns:

  • (String)

    default ”



30
# File 'lib/para_dice/die.rb', line 30

attribute :name, String, default: :quit_if_no_name

#nameString

Returns required.

Returns:

  • (String)

    required



30
# File 'lib/para_dice/die.rb', line 30

attribute :name, String, default: :quit_if_no_name

#rngRandom

Returns default Random.new.

Returns:

  • (Random)

    default Random.new



30
# File 'lib/para_dice/die.rb', line 30

attribute :name, String, default: :quit_if_no_name

Instance Method Details

#face_countObject

This method is abstract.

Implement in Include-able Module and override #face_count to implement a custom Threadable class.



44
45
46
# File 'lib/para_dice/die.rb', line 44

def face_count
  raise NotImplementedError.new ('face_count' + ERROR_MSG)
end

#facesObject

This method is abstract.

Implement in Include-able Module and override #face_count to implement a custom Threadable class.



56
57
58
# File 'lib/para_dice/die.rb', line 56

def faces
  raise NotImplementedError.new ('faces' + ERROR_MSG)
end

#random_face(this_rng = rng) ⇒ Object

This method is abstract.

Implement in Include-able Module and override #face_count to implement a custom Threadable class.



50
51
52
# File 'lib/para_dice/die.rb', line 50

def random_face(this_rng = rng)
  raise NotImplementedError.new ('random_face' + ERROR_MSG)
end

#roll(roll_rng = rng) ⇒ Object

for overloading and calling super on to allow more complex arrangements of

face and dice behavior modules

Parameters:

  • roll_rng (Random) (defaults to: rng)

Returns:

  • (Object)

    random face from die



38
39
40
# File 'lib/para_dice/die.rb', line 38

def roll(roll_rng = rng)
  random_face(roll_rng)
end