# Alphabetical selection from array and element updating

**URL:** <https://www.ruby-forum.com/t/alphabetical-selection-from-array-and-element-updating/178244>\
**Category:** Ruby\
**Created:** [October 31, 2009, 7:30pm UTC](https://www.ruby-forum.com/t/alphabetical-selection-from-array-and-element-updating/178244 "2009-10-31T19:30:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![burrowsm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d78d45/32.png) [@burrowsm](https://www.ruby-forum.com/u/burrowsm)\
**Post date:** [October 31, 2009, 7:30pm UTC](https://www.ruby-forum.com/t/alphabetical-selection-from-array-and-element-updating/178244/1 "2009-10-31T19:30:16Z")

</div>

Writing a crud program where a person would add, delete, update a  
element (Create, Read, Update, Delete).

I have ‘add’ and ‘delete’ figured out. Having trouble with methods for  
updating a element and picking out elements of a particular letter such  
as a person selecting “a” and the method would produce elements in the  
array such as Arthur, Andy, and Aimee.

Here’s the cruddy code (pun intended)

* * *

names = []  
ages = []

hotkey = gets.to\_i  
while hotkey != 10

if hotkey == 3 then  
puts ‘You have selected to update names by their position in the list’  
puts names  
puts ages  
puts ‘From top to bottom, type the record number of which age you wish  
to adjust’

element\_number = gets.to\_i # gets user input from which record is  
selected  
ages.index(element\_number-1) # select record  
# Heres where problems start I need to  
put a element as a integer back in to array and then view array I have  
tried ages.replace but no luck. Any suggestions?

puts names  
puts ages  
puts ‘Would you like to update another name press 10 for no, press 3  
for yes’  
hotkey = gets.to\_i  
end  
end  
puts ‘You have quit’  
print names  
puts ages

* * *

The other problem is viewing people by the first letter of the element  
in the array case insentsitive. Same code as above here is the if loop I  
am working on with method problems.

if hotkey == 5  
puts ‘Type the first letter of the name you wish to view’  
puts names  
a = gets.to\_s  
names.find\_all

{ having trouble passing a from the .gets to this block where a would be  
the letter value of user input. all names with the letter a would be  
displayed for viewing }

puts names  
puts ‘Would you like to choose another menu option press 10 for no,  
press 1,2,3 for yes’  
hotkey = gets.to\_i  
end

Thanks again for the help,

Matt
