-
Notifications
You must be signed in to change notification settings - Fork 1
/
birthday.rb
63 lines (55 loc) · 1.02 KB
/
birthday.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
require 'date'
class Birthday
def today
today = Date.new(Time.now.year, Time.now.month, Time.now.day)
end
def bday
Date.new(@year.to_i, @month.to_i, @day.to_i)
end
def had_bday_this_year?
bday.month < today.month or
(bday.month <= today.month and bday.day < today.day)
end
def calculate_age(bday, today)
if had_bday_this_year?
age = today.year - bday.year
else
age = (today.year - bday.year) - 1
end
age
end
def prompt
puts "When were you born?"
puts "==================="
n = 1
3.times do
if n == 1
print "Year > "
@year = gets.chomp
elsif n == 2
print "Month > "
@month = gets.chomp
else
print "Day > "
@day = gets.chomp
end
n = n + 1
end
end
def print_em
puts "===================="
puts "You are #{calculate_age(bday, today)} years old."
puts "===================="
end
def spank
n = 1
calculate_age(bday, today).times do
puts "Year #{n} > SPANK"
n = n + 1
end
end
end
bd = Birthday.new
bd.prompt
bd.print_em
bd.spank