YAML File Add/Delete

I’m trying to add to a YAML file problem being that when I run the
program the YAML file overwrites the user added. How do I make it
capable of adding other users to the file without overwriting the ones
already added? Also how do you delete from a YAML file?

Here’s the code:

require ‘yaml’

def menu
print “Welcome to User Menu. Would you like to [A]dd users, [D]elete
users, [E]dit users, [V]iew all users, or [E]xit system?\n”
input = gets.chomp!
case input
when /a/i
add_user
when /d/i
delete_user
when /e/i
edit_user
when /v/i
view_all
else
puts “Exiting system…”
exit
end
end

def add_user
puts “Please enter Username:”
username = gets.chomp
data = { username: username }
puts “Please enter user Email:”
email = gets.chomp!
data[:email_address] = email
puts “Please enter users status(member, vip, gold, etc…):”
status = gets.chomp!
data[:member_status] = status
File.open(‘users.yml’, ‘w+’) { |s| s.write(data.to_yaml) }
end

def delete_user
puts “Enter Username to delete:”
end
add_user

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs