管理工具符号错误

时间:2015-11-07 00:32:33

标签: ruby yaml symbols

我今天早些时候发了一篇关于我创建的管理工具的帖子(请参阅帖子here

我被告知重组该计划的某些方面,所以我做到了!现在,我在运行delete_user方法时遇到了不同的错误。

代码:

def delete_user
    hash = YAML.load_file('users.yml')
    to_delete = prompt("Enter username:").to_sym
    if hash[:username] == nil
        puts "Invalid Username.. Redirecting"
        delete_user
    else
        hash[:username].nil?
        hash[:username].delete(to_delete)   
    end
    save_hash(hash)
    delete_user if restart
end

YAML文件概述:

---
:username: TEST
:email_address: TEST
:member_status: TEST
---
:username: TEST1
:email_address: TEST1
:member_status: TEST1

错误:

C:\Users\Justin\MyScripts> ruby usertool.rb
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?
d
Enter username:
TEST
usertool.rb:41:in `delete': no implicit conversion of Symbol into String (TypeEr
ror)
        from usertool.rb:41:in `delete_user'
        from usertool.rb:14:in `menu'
        from usertool.rb:70:in `<main>'
C:\Users\Justin\MyScripts>

这个错误是什么意思?我是否需要在另一个地方拨打.to_sym

0 个答案:

没有答案