class FifthedSim::DiceExpression
This is an abstract dice expression class
Protected Class Methods
define_binary_op_equations(op)
click to toggle source
# File lib/fifthed_sim/dice_expression.rb, line 87 def self.define_binary_op_equations(op) self.send(:define_method, :value_equation) do |terminal: false| lhs = instance_variable_get(:@lhs).value_equation(terminal: terminal) rhs = instance_variable_get(:@rhs).value_equation(terminal: terminal) "(#{lhs} #{op} #{rhs}" end self.send(:define_method, :expression_equation) do lhs = instance_variable_get(:@lhs) rhs = instance_variable_get(:@rhs) "(#{lhs.expression_equation} #{op} #{rhs.expression_equation})" end end
Public Instance Methods
*(other)
click to toggle source
# File lib/fifthed_sim/dice_expression.rb, line 32 def *(other) MultiplicationNode.new(self, other.to_dice_expression) end
+(other)
click to toggle source
# File lib/fifthed_sim/dice_expression.rb, line 20 def +(other) AdditionNode.new(self, other.to_dice_expression) end
-(other)
click to toggle source
# File lib/fifthed_sim/dice_expression.rb, line 24 def -(other) SubtractionNode.new(self, other.to_dice_expression) end
/(other)
click to toggle source
# File lib/fifthed_sim/dice_expression.rb, line 28 def /(other) DivisionNode.new(self, other.to_dice_expression) end
average()
click to toggle source
# File lib/fifthed_sim/dice_expression.rb, line 16 def average distribution.average end
difference_from_average()
click to toggle source
Get this difference of the average value and the current value. For example, if the average is 10 and we have a value of 20, it will return 10. Meanwhile, if the average is 10 and we have a value of 2, it will return -8.
# File lib/fifthed_sim/dice_expression.rb, line 73 def difference_from_average value - average end
max()
click to toggle source
# File lib/fifthed_sim/dice_expression.rb, line 48 def max distribution.max end
min()
click to toggle source
# File lib/fifthed_sim/dice_expression.rb, line 52 def min distribution.min end
or_greater(other)
click to toggle source
# File lib/fifthed_sim/dice_expression.rb, line 36 def or_greater(other) GreaterNode.new(self, other.to_dice_expression) end
or_least(other)
click to toggle source
# File lib/fifthed_sim/dice_expression.rb, line 40 def or_least(other) LessNode.new(self, other.to_dice_expression) end
percentile()
click to toggle source
# File lib/fifthed_sim/dice_expression.rb, line 44 def percentile distribution.percent_lower_equal(value) end
range()
click to toggle source
# File lib/fifthed_sim/dice_expression.rb, line 77 def range (min..max) end
test_then(&block)
click to toggle source
Takes a block, which should take a single argument This block should return another DiceExpression
type, based on the result of this DiceExpression
.
# File lib/fifthed_sim/dice_expression.rb, line 59 def test_then(&block) BlockNode.new(self, &block) end
to_dice_expression()
click to toggle source
# File lib/fifthed_sim/dice_expression.rb, line 81 def to_dice_expression self.dup end
to_f()
click to toggle source
# File lib/fifthed_sim/dice_expression.rb, line 12 def to_f value.to_f end
to_i()
click to toggle source
# File lib/fifthed_sim/dice_expression.rb, line 8 def to_i value end