Class: Dicey::Roller

Inherits:
Object
  • Object
show all
Defined in:
lib/dicey/roller.rb

Overview

Let the dice roll!

Instance Method Summary collapse

Instance Method Details

#call(arguments, format:) ⇒ nil

Parameters:

  • arguments (Array<String>)

    die definitions

  • format (#call)

    formatter for output

Returns:

  • (nil)

Raises:



12
13
14
15
16
17
18
19
# File 'lib/dicey/roller.rb', line 12

def call(arguments, format:, **)
  raise DiceyError, "no dice!" if arguments.empty?

  dice = arguments.flat_map { |definition| die_foundry.cast(definition) }
  result = dice.sum(&:roll)

  format.call({ "roll" => result }, AbstractDie.describe(dice))
end