-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruby_functions_practice.rb
63 lines (51 loc) · 1014 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
def return_10
return 10
end
def add(a,b)
return a+b
end
def subtract(a,b)
return a-b
end
def multiply(a, b)
return a*b
end
def divide(a,b)
return a/b
end
def length_of_string(string)
return string.length
end
def join_string(s1, s2)
return s1 << s2
end
def add_string_as_number(s1, s2)
return s1.to_i + s2.to_i
end
def number_to_full_month_name(number)
month = { 1 => "January",
2 => "February",
3 => "March",
4 => "April",
5 => "May",
6 => "June",
7 => "July",
8 => "August",
9 => "September",
10 => "October",
11 => "November",
12 => "December" }
return month[number]
end
def number_to_short_month_name(number)
return number_to_full_month_name(number)[0..2]
end
def volume_of_cube(r)
return r**3
end
def volume_of_sphere(r)
return (4.0/3.0)* MATH::PI * r**3.round(2)
end
def test_fahrenheit_to_celsius(f)
return ((f-32)*0.5556).round(0)
end