Class: FifthedSim::NumberNode
Overview
Normally we handle numbers by use of a refinement on Fixnum However, in some cases, we may have the fixnum as the start of an expression. In this case, we have a problem, because Fixnum#+ is not overloaded to return a DiceNode. In this case, we must use this, a NumberNode. NumberNodes wrap a number.
Instance Method Summary
collapse
#*, #+, #-, #/, #average, #difference_from_average, #max, #min, #or_greater, #or_least, #percentile, #range, #test_then, #to_dice_expression, #to_f, #to_i
Constructor Details
Returns a new instance of NumberNode.
11
12
13
14
15
16
|
# File 'lib/fifthed_sim/nodes/number_node.rb', line 11
def initialize(arg)
unless arg.is_a? Fixnum
raise ArgumentError, "#{arg.inspect} is not a fixnum"
end
@value = arg
end
|
Instance Method Details
#distribution ⇒ Object
18
19
20
|
# File 'lib/fifthed_sim/nodes/number_node.rb', line 18
def distribution
Distribution.for(@value)
end
|
#expression_equation ⇒ Object
34
35
36
|
# File 'lib/fifthed_sim/nodes/number_node.rb', line 34
def expression_equation
@value.to_s
end
|
#reroll ⇒ Object
26
27
28
|
# File 'lib/fifthed_sim/nodes/number_node.rb', line 26
def reroll
self.class.new(@value)
end
|
#value ⇒ Object
22
23
24
|
# File 'lib/fifthed_sim/nodes/number_node.rb', line 22
def value
@value
end
|
#value_equation(terminal: false) ⇒ Object
30
31
32
|
# File 'lib/fifthed_sim/nodes/number_node.rb', line 30
def value_equation(terminal: false)
@value.to_s
end
|