Class: RpgLib::DiceRoller
- Inherits:
-
Object
- Object
- RpgLib::DiceRoller
- Includes:
- Singleton
- Defined in:
- lib/rpg_lib/dice_roller.rb
Overview
DiceRoller
Instance Attribute Summary collapse
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#roller ⇒ Object
Returns the value of attribute roller.
Instance Method Summary collapse
-
#initialize ⇒ DiceRoller
constructor
A new instance of DiceRoller.
- #roll(dice) ⇒ Object
- #roll_and_ignore(dice, ignored_values) ⇒ Object
- #roll_die(n) ⇒ Object
Constructor Details
#initialize ⇒ DiceRoller
Returns a new instance of DiceRoller.
30 31 32 33 |
# File 'lib/rpg_lib/dice_roller.rb', line 30 def initialize @roller = DieRoller.new @parser = Parser::DiceParser.new end |
Instance Attribute Details
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
27 28 29 |
# File 'lib/rpg_lib/dice_roller.rb', line 27 def parser @parser end |
#roller ⇒ Object
Returns the value of attribute roller.
28 29 30 |
# File 'lib/rpg_lib/dice_roller.rb', line 28 def roller @roller end |
Instance Method Details
#roll(dice) ⇒ Object
39 40 41 |
# File 'lib/rpg_lib/dice_roller.rb', line 39 def roll(dice) @parser.parse(dice).eval(@roller) end |
#roll_and_ignore(dice, ignored_values) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/rpg_lib/dice_roller.rb', line 43 def roll_and_ignore(dice, ignored_values) loop do rolled_value = roll(dice) return rolled_value unless ignored_values.include?(rolled_value) end end |
#roll_die(n) ⇒ Object
35 36 37 |
# File 'lib/rpg_lib/dice_roller.rb', line 35 def roll_die(n) @roller.roll(n) end |