dice 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/bin/roll +8 -0
  2. data/lib/dice.rb +23 -0
  3. metadata +55 -0
data/bin/roll ADDED
@@ -0,0 +1,8 @@
1
+ #! /usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../lib/dice'
3
+
4
+ if ARGV.length == 0
5
+ puts 'Usage: roll D20'
6
+ else
7
+ puts eval(ARGV.first).inspect
8
+ end
data/lib/dice.rb ADDED
@@ -0,0 +1,23 @@
1
+ def Object.const_missing name
2
+ if name.to_s =~ /^D(\d+)$/
3
+ Die.new($1).roll
4
+ elsif name.to_s =~ /^D(\d+)x(\d+)$/
5
+ Die.new($1).roll($2)
6
+ else
7
+ super
8
+ end
9
+ end
10
+
11
+ class Die
12
+
13
+ def initialize sides=20
14
+ @sides = sides.to_i
15
+ end
16
+
17
+ def roll number = 1
18
+ rolls = []
19
+ number.to_i.times { rolls << (rand(@sides) + 1).to_i }
20
+ rolls
21
+ end
22
+
23
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dice
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors: []
7
+
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-03 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email:
18
+ executables:
19
+ - roll
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/dice.rb
26
+ has_rdoc: true
27
+ homepage:
28
+ licenses: []
29
+
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project:
50
+ rubygems_version: 1.3.3
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: Dice are delicious!
54
+ test_files: []
55
+