Rubyリファレンスでエンティティヘッダーを取得するプログラムが
あったのですが
ruby
1require 'net/http' 2require 'uri' 3#http://www.example.com/index.html 4 5response = nil 6Net::HTTP.start('www.example.com'){|http| 7 response = http.head('/index.html') 8} 9puts response['content-type'] 10
この
ruby
1response = nil
これはなぜ必要なのですか?
これ以外のコードならわかるのですが。。。
ruby
1require 'net/http' 2require 'uri' 3#http://www.example.com/index.html 4 5Net::HTTP.start('www.example.com'){|http| 6 response = http.head('/index.html') 7} 8puts response['content-type'] 9
上記のようにnilを外すとエラーになります。
なぜ response=nilを外すとエラーになるのか
参考になるリンクまたは説明をお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/21 14:56