-1

我有返回下一个哈希对象的 gem

{:response=>"There was an error authenticating the sender account.", :status_code=>401}

在我的 rake 任务中,我试图访问它的属性:

response = my_gem.execute
puts response
puts response.has_key?(:respose)
puts response[:respose]

但我不明白为什么会打印

{:response=>"There was an error authenticating the sender account.", :status_code=>401}
false

为什么我不能使用 response[:respose] 访问 :response 属性?

PS response[response.keys.first] 有效,但这是非常奇怪的解决方案

4

1 回答 1

3

There is a typo in the below :

puts response.has_key?(:respose)

has_key?(:respose) should be has_key?(:response).

response = {:response=>"There was an error authenticating the sender account.", :status_code=>401}
response.has_key?(:response)
# => true
于 2013-07-03T14:12:00.217 回答