Class: Hazard
- Inherits:
-
Object
- Object
- Hazard
- Defined in:
- lib/hazard.rb,
lib/hazard/version.rb
Overview
This class roll the dice.
Constant Summary collapse
- DICE_NAME_REGEXP =
/(d|r|m|s)?(\d*)d(\d+)/.freeze
- VERSION =
'1.3.4'
Class Method Summary collapse
-
.from_string(dice_string) ⇒ Object
From string entry point, in case you have your dice description in a database for instance.
-
.lucky?(dice) ⇒ Boolean
Roll a dice and return true if you rolled the highest number.
-
.method_missing(method_name) ⇒ Object
Regular entry point.
-
.respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Hook the method_missing.
Class Method Details
.from_string(dice_string) ⇒ Object
From string entry point, in case you have your dice description in a database for instance.
31 32 33 |
# File 'lib/hazard.rb', line 31 def self.from_string( dice_string ) roll_dice( dice_string ) end |
.lucky?(dice) ⇒ Boolean
Roll a dice and return true if you rolled the highest number
45 46 47 |
# File 'lib/hazard.rb', line 45 def self.lucky?( dice ) roll_dice( "d#{dice}" ) == dice end |
.method_missing(method_name) ⇒ Object
Regular entry point. This is where you will go when you call Hazard.d6 for instance.
16 17 18 19 20 21 22 23 24 |
# File 'lib/hazard.rb', line 16 def self.method_missing( method_name ) method_name = method_name.to_s if method_name =~ DICE_NAME_REGEXP roll_dice( method_name ) else super end end |
.respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Hook the method_missing
36 37 38 |
# File 'lib/hazard.rb', line 36 def self.respond_to_missing?(method_name, include_private = false) method_name.to_s =~ DICE_NAME_REGEXP || super end |