Skip to content

Instantly share code, notes, and snippets.

@dirceu
Created July 23, 2008 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dirceu/1508 to your computer and use it in GitHub Desktop.
Save dirceu/1508 to your computer and use it in GitHub Desktop.
# Author: Dirceu Pereira Tiegs <dirceutiegs@gmail.com>
#
# 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