-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbeers.rb
97 lines (82 loc) · 1.31 KB
/
beers.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# encoding: utf-8
module Beer
EMOJI = "🍺 "
DOUBLE_EMOJI = "🍻 "
ERROR = "🚨 🚔 🚔 🚔 🚨 "
end
class Fixnum
def beers
Beer::EMOJI * self
end
def double_beers
Beer::DOUBLE_EMOJI * self
end
def pack
if self == 6
print_pack(2, 3)
elsif self == 12
print_pack(2, 6)
elsif self == 18
print_pack(3, 6)
elsif self == 24
print_pack(4, 6)
elsif self == 30
print_pack(5, 6)
else
raise BeerError.new
end
end
alias beer beers
private
def print_pack(rows, cols)
(cols.beers + "\n") * rows
end
end
class BeerError < RuntimeError
def self.class
Class.new do
def to_s
Beer::ERROR
end
end
end
def to_s
Beer::ERROR
end
end
class String
def compact
(length / 4).double_beers + ((length % 4) / 2).beers
end
def inspect
"\n" + to_s
end
end
class Random
def self.beers(num = nil)
# if you know the upper limit, you'll always want the maximum
# number of beers, anyway
if num
num.ceil - 1
else
rand(100)
end.beers
end
end
class Time
def beer?
true
end
end
module Find
def self.beer
Enumerator.new do |y|
loop do
y << Beer::EMOJI
end
end
end
end
puts "Loading BEER FRAMEWORK"
sleep 2
puts "... loaded!"