Class: FifthedSim::NumberNode

Inherits:
DiceExpression show all
Defined in:
lib/fifthed_sim/nodes/number_node.rb

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

Methods inherited from DiceExpression

#*, #+, #-, #/, #average, #difference_from_average, #max, #min, #or_greater, #or_least, #percentile, #range, #test_then, #to_dice_expression, #to_f, #to_i

Constructor Details

#initialize(arg) ⇒ NumberNode

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

#distributionObject



18
19
20
# File 'lib/fifthed_sim/nodes/number_node.rb', line 18

def distribution
  Distribution.for(@value)
end

#expression_equationObject



34
35
36
# File 'lib/fifthed_sim/nodes/number_node.rb', line 34

def expression_equation
  @value.to_s
end

#rerollObject



26
27
28
# File 'lib/fifthed_sim/nodes/number_node.rb', line 26

def reroll
  self.class.new(@value)
end

#valueObject



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