Class: ParaDice::Results::Number
- Inherits:
-
Object
- Object
- ParaDice::Results::Number
- Defined in:
- lib/para_dice/results/number.rb
Overview
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
Constant Summary collapse
- DEFAULT_INITIAL =
If not overridden the initial value is 0
0- DEFAULT_OPERATOR =
If not overridden the operator is :+
:+
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(initial_val = DEFAULT_INITIAL, default_operator = DEFAULT_OPERATOR) ⇒ Number
constructor
A new instance of Number.
-
#resolve(faces, initial_value = default_initial_value, operator = default_operator) ⇒ Numeric, Object
Result of inject with faces, initial_value, and operator.
Constructor Details
#initialize(initial_val = DEFAULT_INITIAL, default_operator = DEFAULT_OPERATOR) ⇒ Number
Returns a new instance of Number.
25 26 27 28 |
# 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 |
Instance Attribute Details
#default_initial_value ⇒ Numeric, Obj
21 22 23 |
# File 'lib/para_dice/results/number.rb', line 21 def default_initial_value @default_initial_value end |
#default_operator ⇒ Symbol
21 |
# File 'lib/para_dice/results/number.rb', line 21 attr_accessor :default_initial_value, :default_operator |
Instance Method Details
#resolve(faces, initial_value = default_initial_value, operator = default_operator) ⇒ Numeric, Object
Returns result of inject with faces, initial_value, and operator.
34 35 36 |
# 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 |