-
Notifications
You must be signed in to change notification settings - Fork 1
/
ruby_functions_practice.rb
68 lines (56 loc) · 1001 Bytes
/
ruby_functions_practice.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
def return_10
return 10
end
def add(x,y)
return x + y
end
def subtract(x,y)
return x - y
end
def multiply(x,y)
return x * y
end
def divide(x,y)
return x / y
end
def length_of_string(string)
return string.length
end
def join_string(x, y)
return x + y
end
def add_string_as_number(x,y)
return x.to_i + y.to_i
end
def number_to_full_month_name(month_nr)
if month_nr == 1
return "January"
elsif month_nr == 3
return "March"
elsif month_nr == 9
return "September"
else
return nil
end
end
def number_to_short_month_name(month_nr)
if month_nr == 1
return "Jan"
elsif month_nr == 4
return "Apr"
elsif month_nr == 10
return "Oct"
else
return nil
end
end
def volume_of_cube(side)
return side ** 3
end
def volume_of_sphere(radius)
# .round(2) rounds the number to the hundredth of a decimal
return (4.0/3 * Math::PI * radius**3).round(2)
end
def convert_f_to_c(degree_f)
return (degree_f - 32) * 5/9
end