class ParaDice::Results::Number
@note this class could also be used for more complex operations using the
reduce with operator and initial values. Blocks seem like another likely refinement. But I couldn't come with a reason to use them yet that didn't seem more confusing than coding a new result resolver
Constants
- DEFAULT_INITIAL
If not overridden the initial value is 0
- DEFAULT_OPERATOR
If not overridden the operator is :+
Attributes
default_initial_value[RW]
@!attribute [rw] default_initial_value
@return [Numeric,Obj]
@!attribute [rw] default_operator
@return [Symbol]
default_operator[RW]
@!attribute [rw] default_initial_value
@return [Numeric,Obj]
@!attribute [rw] default_operator
@return [Symbol]
Public Class Methods
new(initial_val = DEFAULT_INITIAL, default_operator = DEFAULT_OPERATOR)
click to toggle source
@param [Numeric, Obj] default_operator
@param [Symbol] default_operator
# File lib/para_dice/results/number.rb, line 25 def initialize(initial_val = DEFAULT_INITIAL, default_operator = DEFAULT_OPERATOR) @default_initial_value = initial_val @default_operator = default_operator end
Public Instance Methods
resolve(faces, initial_value = default_initial_value, operator = default_operator)
click to toggle source
@param [Array<Numeric,Object>] faces @param [Numeric,Object] initial value, defaults to DEFAULT_INITIAL
= 0 @param [Symbol] operator, defaults to DEFAULT_OPERATOR
= :+ @return [Numeric, Object] result of inject with faces, initial_value, and operator
# File lib/para_dice/results/number.rb, line 34 def resolve(faces, initial_value = default_initial_value, operator = default_operator) faces.inject(initial_value, operator) end