Created
July 23, 2008 03:35
-
-
Save dirceu/1508 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Dirceu Pereira Tiegs <[email protected]> | |
# | |
# Script to roll dices (used to play D&D). Example: | |
# | |
# >> require 'dices' | |
# >> 3.d6 | |
# => 10 | |
# >> 3.d6+7 | |
# => 14 | |
# >> 1.d4+2.d8+1.d12+3 | |
# => 32 | |
# | |
class Numeric | |
def method_missing(methodname, *args) | |
dice = methodname.to_s | |
if %w[d2 d3 d4 d6 d8 d10 d12 d20 d100].include? dice | |
self * (rand(dice[1..4]) + 1) | |
else | |
self.send(methodname, *args) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment