module ParaDice::Faces::Arrayed
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
Public Instance Methods
face_count()
click to toggle source
returns size of array @return [Fixnum]
# File lib/para_dice/faces/arrayed.rb, line 19 def face_count faces.size end
random_face(r = rng)
click to toggle source
returns a random face from faces using rng @return [String]
# File lib/para_dice/faces/arrayed.rb, line 25 def random_face(r = rng) faces.sample(random: r) end
Private Instance Methods
quit_if_no_faces()
click to toggle source
# File lib/para_dice/faces/arrayed.rb, line 30 def quit_if_no_faces raise ArgumentError.new('no :faces entry found in initialization hash') end