-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCRUD.rb
67 lines (62 loc) · 1.34 KB
/
CRUD.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
puts '*******CRUD with an array*******'
names = [
'Satish',
'Talim',
'Ruby',
'Java'
]
def create(names)
puts '---------*Insert new*---------'
puts 'Enter a name:'
new_name = gets.chomp
names << new_name
puts '**Successful**'
puts '----------------------'
end
def read(names)
puts '---------View elements---------'
names.each_with_index do |element, index|
puts "#{index}: #{element}"
end
puts '------------------'
end
def update(names)
puts '---------*Update*---------'
read(names)
puts 'select one element of above: '
position = gets.to_i
puts 'enter a name:'
edit_name = gets.chomp
puts '**Successful**'
puts "#{names[position]} changed by #{edit_name}"
names[position] = edit_name
puts '----------------------'
end
def delete(names)
puts '---------*Delete*---------'
read(names)
puts 'Select one element: '
position = gets.to_i
names.delete_at(position)
puts '**deleted**'
puts '----------------------'
end
loop do
puts 'Choose a option:'
puts '1.- Insert new'
puts '2.- View elements'
puts '3.- Update'
puts '4.- Delete'
puts "0.- The program ends\n"
puts "\n"
print 'Write the option: '
option = gets.chomp.to_i
case option
when 0 then break
when 1 then create(names)
when 2 then read(names)
when 3 then update(names)
when 4 then delete(names)
else 'Error'
end
end