Class: Fixnum

Inherits:
Object
  • Object
show all
Defined in:
lib/fifthed_sim/dice_expression.rb,
lib/fifthed_sim.rb,
lib/fifthed_sim/nodes/multi_node.rb

Overview

We sneakily monkey-patch Fixnum here, to allow us to use a nice syntax for factorials.

We only do this if somebody hasn’t done it already, in case ruby adds this to the standard one day.

Instance Method Summary collapse

Instance Method Details

#d(o) ⇒ Object

Enable you to create dice rolls via ‘3.d(6)` syntax. This returns a DiceResult, meaning that you can add them together to form a calculation.



37
38
39
# File 'lib/fifthed_sim.rb', line 37

def d(o)
  FifthedSim.d(self, o)
end

#factorialObject

Mathematical factorial



13
14
15
# File 'lib/fifthed_sim/nodes/multi_node.rb', line 13

def factorial
  (1..self).inject(:*) || 1
end

#to_dice_expressionObject



106
107
108
# File 'lib/fifthed_sim/dice_expression.rb', line 106

def to_dice_expression
  FifthedSim::NumberNode.new(self)
end