gpt4 book ai didi

ruby-on-rails - 构建哈希时字符串化键错误

转载 作者:太空宇宙 更新时间:2023-11-03 17:51:50 25 4
gpt4 key购买 nike

我收到一个 stringify_keys 错误。

目前我正在调用以下完美运行的方法:

def attributes
{
city: @content[1..20].strip,
streetname: @content[21..40].strip,
house_number: @content[41..46].strip.to_i
}
end

现在我正在重构我的代码,我需要从头开始构建哈希,其中键和值根据特定条件(条件尚未写入)填充哈希。

def attributes
test = {}
test["city"] = @content[1..20].strip
test["streetname"] = @content[21..40].strip
test["house_number"] = @content[41..46].strip.to_i
end

现在我收到了 stringify_keys 错误。我查看了文档以获取有关如何构建哈希的线索,但没有任何可以帮助我的东西。

问题出在哪里?如果您需要更多代码,请询问。

最佳答案

第一段代码的关键是symbol,第二段代码最后要返回test

def attributes
test = {}
test[:city] = @content[1..20].strip
test[:streetname] = @content[21..40].strip
test[:house_number] = @content[41..46].strip.to_i
test
end

关于ruby-on-rails - 构建哈希时字符串化键错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23489378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com