-
Notifications
You must be signed in to change notification settings - Fork 0
/
methodsgalore.rb
50 lines (46 loc) · 962 Bytes
/
methodsgalore.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
def rect_area (length, width)
return length*width
end
def tbsp2cup(tbsp)
return tbsp/16.0
end
def cups2tbsp(cups)
return cups*16.0
end
def torf(number1, number2)
if number1%number2 == 0
return true
else
return false
end
end
def rect_compare(length_one, width_one, length_two, width_two)
rect_one = length_one*width_one
rect_two = length_two*width_two
if rect_one > rect_two
return "Rectangle one"
elsif rect_two > rect_one
return "Rectangle two"
else
return "They are the same."
end
end
class Rect
attr_reader :length, :width
def initialize(length, width)
@length = length
@width = width
end
end
def area(rectangle)
return rectangle.length*rectangle.width
end
def compare(rectangle_one, rectangle_two)
if area(rectangle_one) > area(rectangle_two)
return rectangle_one
elsif area(rectangle_two) > area(rectangle_one)
return rectangle_two
else
return "They are the same."
end
end