I've created a Forum website tool for admins to add, edit, and delete users from their desktop, saving to a file, and uploading the file to the database, the program is not completed I'm posting it here for review thus far (People I'm creating it for would prefer me not having access to database, I understand I would be using activerecord model/structure if I where saving directly to the database.)What the program does is simple:It prompts the user for which he/she would like to do via add, edit,delete users.The program then runs through a case statement of available optionsand if the option isn't found it exits the programIn the add_user method the program saves the input of the user into a YAML file, and prompts the user for more users, if none follow exits the program.During the delete_user method, the program does the same as adding except deletes the users from the YAML file there is a bug where the program deletes the entire YAML file, not just the edited usersIn the edit_user the program will edit various elements of the hash inside the YAML file and save over the old element of the file. Not ready yet will post follow up laterThe edit user section hasn't been setup yet, still working out the kinks in delete_user method.So what I'm looking for is: A possible explanation of why the delete_user method wipes theentire file and not just the user entered, is this because I'm deletingthe entire section and not just the users input?Would using a JSON file be better then using a YAML file, I'm awarethat A LOT of websites don't support YAML's so would it be a good idea to convert the require 'yaml' to a require 'json' and regroup from there? Any possible areas of improvement? Meaning do you notice anythingright off the bat that should be changed, can my syntax be updated or more developed?Source Code:#!/usr/bin/env rubyrequire 'yaml'require 'open-uri'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 [Q]uit the 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    endenddef 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', 'a') { |s| s.write(data.to_yaml) }    add_user if restartenddef delete_user    puts Enter Username:    username = gets.chomp    delete_data = {username: username}    puts Enter Email:    email = gets.chomp    delete_data[:email_address] = email    puts Enter Status:    status = gets.chomp    delete_data[:status] = status    hash = YAML.load_file('users.yml')    hash.delete(#{username})    hash.delete(#{email})    hash.delete(#{status})    File.open('users.yml', 'w') { |f| YAML.dump(delete_data.to_yaml) }    delete_user if restartenddef edit_user    edit_user if restartenddef view_all    content = URI('#Website URL here taken out for security of site').readenddef restart    puts Would you like to edit another user?    input = gets.chomp    if input =~ /yes/i        return true    else        puts Exiting program..        exit    endendmenuOverview of YAML file:--- :username: TEST:email_address: TEST:member_status: TEST
Usertool to Edit Forum Members from Desktop
ruby;yaml
prompt functionSo many times you do:puts Please enter Username: # Or something else instead of Username.username = gets.chompIn short you print and then read input, what about a function:def prompt(message)  puts message  gets.chompendYou can reuse it and save a lot of repetition.Functional Programming -- No mutationRuby leans towards the Function Programming paradigm, so you should stick to it.One thing is avoiding mutation:data = {username: username}...data[:email_address] = email...data[:member_status] = statusYou modify data piece by piece, instead do:......data = {username: username, email_address: email, member_status: status}It also looks more organized to me.In fact you may write:data = { username: prompt(The username? ),         email_address: prompt(The email address? )         member_status: prompt(The member status? ) }And make the code shorter and more readable.