forked from appdev-projects/sinatra-dice-roll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdice.rb
70 lines (54 loc) · 992 Bytes
/
dice.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require "sinatra"
require "sinatra/reloader"
require "better_errors"
require "binding_of_caller"
use(BetterErrors::Middleware)
BetterErrors.application_root = __dir__
BetterErrors::Middleware.allow_ip!('0.0.0.0/0.0.0.0')
get("/") do
erb(:home)
end
get("/") do
"Hello World"
end
get("/zebra") do
"We must add a route for each path we want to support"
end
get("/giraffe") do
"Hopefully this shows up without having to restart the server"
end
get("/dice/2/6") do
@rolls = []
2.times do
@rolls.push(rand(1..6))
end
erb(:two_six)
end
get("/dice/2/10") do
@rolls = []
2.times do
@rolls.push(rand(1..10))
end
erb(:two_ten)
end
get("/dice/1/20") do
@rolls = []
1.times do
@rolls.push(rand(1..20))
end
erb(:one_twenty)
end
get("/dice/5/4") do
@rolls = []
5.times do
@rolls.push(rand(1..4))
end
erb(:five_four)
end
get("/dice/100/6") do
@rolls = []
100.times do
@rolls.push(rand(1..6))
end
erb(:one_hundred_six)
end