-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsteak.rb
More file actions
39 lines (31 loc) · 864 Bytes
/
steak.rb
File metadata and controls
39 lines (31 loc) · 864 Bytes
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
class Steak
GRADE_SCORES = {"Prime" => 3, "Choice" =>2, "Select" => 1}
include Comparable
attr_accessor :grade
def <=> (other)
if GRADE_SCORES[self.grade] < GRADE_SCORES[other.grade]
return -1
elsif GRADE_SCORES[self.grade] == GRADE_SCORES[other.grade]
return 0
else
return 1
end
end
end
first_steak = Steak.new
first_steak.grade = "Prime"
second_steak = Steak.new
second_steak.grade = "Choice"
prime = Steak.new
prime.grade = "Prime"
choice = Steak.new
choice.grade = "Choice"
select = Steak.new
select.grade = "Select"
puts "prime > choice: #{prime > choice}"
puts "prime < select: #{prime < select}"
puts "select == select: #{select == select}"
puts "select <= select: #{select <= select}"
puts "select >= choice: #{select >= choice}"
print "choice.between?(select, prime): "
puts choice.between?(select, prime)