我正在使用 Cinch IRC 框架制作一个报价功能,允许用户对报价进行 CRUD。
我遇到了问题;我的迭代基于 cinch-quote gem,它使用 YAML 来存储引号。
它将 YAML 中的引号加载到多维散列中。delete_quote 方法需要通过 ID 找到标记的报价,并在 YAML 数据库中将其标记为“已删除”。我遇到的问题是在此 YAML 数据库中将已删除的值从 false 更改为 true。我是 ruby 新手,这段代码可能非常糟糕和可笑,请残酷。
def get_quotes
output = File.new(@quotes_file, 'r')
quotes = YAML.load(output.read)
output.close
quotes
end
def delete_quote(m, search = nil)
if is_admin?(m) && search.to_i > 0
quotes = get_quotes
quote = quotes.find { |q| q["id"] == search.to_i }
#debugging stuff
#returns the master quote hash
p quotes
#returns the hash that i'm trying to change.
p quote
if quote.nil?
message_type(m, "Quote ID #{search} does not exist.")
else
#again, master hash
output = YAML.load_file(@quotes_file)
#here's the error. Can't convert Hash into Integer. I can't figure out why
# it'd be generating that, or how to fix it.
mark_delete = output[quote]["deleted"] = "true"
message_type(m, "Quote #{search} was deleted")
end
end
end