Ruby - 哈希,符号和字符串

时间:2013-07-03 14:08:50

标签: ruby-on-rails ruby gem rake

我有返回下一个哈希对象的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

为什么我无法访问:带有响应的响应属性[:respose]?

P.S。响应[response.keys.first]有效,但这是非常奇怪的解决方案

1 个答案:

答案 0 :(得分:3)

下面有一个拼写错误:

puts response.has_key?(:respose)

has_key?(:respose)应为has_key?(:response)

response = {:response=>"There was an error authenticating the sender account.", :status_code=>401}
response.has_key?(:response)
# => true