我试图在HttpParty :: Response的实例上使用ActiveSupport(2.3-stable)try()。我有一个很奇怪的行为:HttpParty ::响应和尝试(:parsed_response)奇怪的行为
> ro.parsed_response
{"error"=>"RecordInvalid", "description"=>"Record validation errors", "details"=>{"email"=> [{"description"=>"Email: [email protected] is already taken by another user"}]}}
> ro.try(:parsed_response)
NoMethodError Exception: undefined method `parsed_response' for #<Hash:0x11397d5d8>
在第一个例子中,我使用点符号发送parsed_response消息给ro。它工作正常。在第二个中,我尝试使用ActiveSupport的try()来调用它,并且(令人惊讶地)引发了NoMethodError异常。
不应该尝试()返回nil在这种情况下?为什么它找不到“parsed_response”方法,如果我可以使用点符号来调用它,如第一个例子所示?
在此先感谢!
你是红宝石1.8吗? – ted 2013-04-11 00:04:35
嗨特德,是的,我在Ruby 1.8.7上。 – FullOfCaffeine 2013-04-11 19:32:45