-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15.rb
More file actions
53 lines (45 loc) · 965 Bytes
/
15.rb
File metadata and controls
53 lines (45 loc) · 965 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
movies = {
"movie1" => 5,
"movie2" => 4,
"movie3" => 3
}
puts "Enter your choice"
choice = gets.chomp
case choice
when "add"
puts "Enter movie title"
title = gets.chomp
puts "Enter rating"
rating = gets.chomp
if movies[title].nil?
movies[title.to_sym] = rating.to_i
puts "#{title} has been added with a rating of #{rating}."
else
puts "Title already exists"
end
when "update"
puts "Enter title to update"
title = gets.chomp
if movies[title].nil?
puts "Error! Invalid title"
else
puts "Enter new rating"
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts "#{title} has been updated with a rating of #{rating}."
end
when "display"
movies.each do |movie, rating| puts "#{movie}: #{rating}"
end
when "delete"
puts "Enter movie title to delete"
title = gets.chomp
if movies[title].nil?
puts "Error! Invalid Title"
else
movies.delete(title)
puts "#{title} has been deleted"
end
else
puts "Error!"
end