Skip to content

Instantly share code, notes, and snippets.

@a2ikm
Created November 13, 2010 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a2ikm/675476 to your computer and use it in GitHub Desktop.
Save a2ikm/675476 to your computer and use it in GitHub Desktop.
run webrick
#!/usr/bin/env ruby
require 'optparse'
require 'webrick'
include WEBrick
# WEBrickを起動する際のオプションのデフォルト値
WebrickOptions = {
:Port => 8000,
:DocumentRoot => Dir::pwd,
}
OptionParser.new do |opt|
# パース方法を設定する
# オプションが指定されていた場合にブロックが評価される
opt.on('-p', '--Port N', Integer) { |v| WebrickOptions[:Port] = v }
opt.on('-d', '--DocumentRoot PATH') { |v| WebrickOptions[:DocumentRoot] = v }
# 実際にパースを行う
opt.parse!(ARGV)
end
# WEBrickを起動する
s = HTTPServer.new(WebrickOptions)
trap("INT") { s.shutdown }
s.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment