Rubyでエンティティヘッダーを取得するプログラムを作りました。
第一引数に URLのホスト
第二引数に パス
です。
ruby
1require 'net/http' 2 3host_name = if ARGV[0] then ARGV[0] else false end 4path = if ARGV[1] then ARGV[1] else false end 5 if ARGV[0] == false or ARGV[1] == false 6 puts "コマンド引数がありません" 7 end 8http = Net::HTTP.new(host_name) 9response_header = http.head(path) 10response_header.each do |name,value| 11 puts name + ":" +value 12end
本題
実装したいのはコマンド引数がないときは
ruby
1puts "コマンド引数がありません
上記を実行するプログラムを作りたいです。
そこで、以下のようにしたのですが。。。
ruby
1require 'net/http' 2 3host_name = if ARGV[0] then ARGV[0] else false end 4path = if ARGV[1] then ARGV[1] else false end 5 if ARGV[0] == false or ARGV[1] == false 6 puts "コマンド引数がありません" 7 end 8http = Net::HTTP.new(host_name) 9response_header = http.head(path) 10response_header.each do |name,value| 11 puts name + ":" +value 12end
しかし
ruby
1puts "コマンド引数がありません"
これが実行されません。
どうやったら出てくれるのでしょうか?
分からないので参考になるリンクまたは説明をお願いします。
回答4件
あなたの回答
tips
プレビュー