爲rest_client gem有以下示例中的文件:參數傳遞給塊
RestClient.get('http://my-rest-service.com/resource'){ |response, request, result, &block|
case response.code
when 200
p "It worked !"
response
when 423
raise SomeCustomExceptionIfYouWant
else
response.return!(request, result, &block)
end
}
你怎麼知道什麼屬性可在上述每個塊的變量? response
,request
等分別具有哪些屬性?當我運行rest_client
:
response = RestClient.get('http://www.google.com')
很多東西都返回response
:
response.instance_variables # => [:@net_http_res, :@args, :@request, :@code]
response.net_http_res # => #<Net::HTTPOK 200 OK readbody=true>
response.args # => {:method=>:get, :url=>"http://www.google.com", :headers=>{}}
response.code # => 200
哪些部分的response
可用來塊?參數的順序是否重要?