Module: ParaDice::Faces::Arrayed

Includes:
Die
Included in:
StringDie
Defined in:
lib/para_dice/faces/arrayed.rb

Overview

a module to be included into a ParaDice::Die or similar object.

Uses an Array object to provide faces, and provides count and
random_face methods

@note, these are strings, but the pattern could easily be symbols, numbers,

json objects, etc.  the only difference would be in how you

Constant Summary

Constants included from Die

Die::ERROR_MSG

Instance Attribute Summary collapse

Attributes included from Die

#description, #name, #rng

Instance Method Summary collapse

Methods included from Die

#roll

Instance Attribute Details

#facesObject



15
# File 'lib/para_dice/faces/arrayed.rb', line 15

attribute :faces, Array[String], default: :quit_if_no_faces

Instance Method Details

#face_countFixnum

returns size of array

Returns:

  • (Fixnum)


19
20
21
# File 'lib/para_dice/faces/arrayed.rb', line 19

def face_count
  faces.size
end

#random_face(r = rng) ⇒ String

returns a random face from faces using rng

Returns:

  • (String)


25
26
27
# File 'lib/para_dice/faces/arrayed.rb', line 25

def random_face(r = rng)
  faces.sample(random: r)
end