这是确切的问题;
$ hash
=> {:createAuthenticationTokenRequest=>{:playerSessionID=>"111"}}
$ hash[:attributes!]
=> "" (here is the crazy result)
$ hash.class
=> Hash
$ hash.keys
=> [:createAuthenticationTokenRequest]
这里发生了什么?对于不存在的哈希键,我不应该得到 nil 吗?
详细问题:
我正在使用 savon 发送 Web 服务请求,并且一直收到“无法将符号转换为整数”错误,使用 pry 调试错误表明该行正在作为空字符串执行,这是不应该的。
attributes = hash[:attributes!] || {}
帮帮我!
提前谢谢,干杯!
更新:回答如何创建哈希;
class Gyoku::Hash
def self.iterate_with_xml(hash)
xml = Builder::XmlMarkup.new
attributes = hash[:attributes!] || {}
Update2:这是我发送的请求
request(
createAuthenticationTokenRequest: {
playerSessionID: "111"
}
)
正如我之前提到的,这是被执行的 savon gem 代码。我试图把这个问题写得尽可能不那么无聊,但不明白为什么它会被否决:/
这是被调试的源代码。
https://github.com/savonrb/gyoku/blob/master/lib/gyoku/hash.rb