Skip to content

Instantly share code, notes, and snippets.

@mattstifanelli
Created May 12, 2011 14:52
Show Gist options
  • Save mattstifanelli/968660 to your computer and use it in GitHub Desktop.
Save mattstifanelli/968660 to your computer and use it in GitHub Desktop.
The script launch a web server on port 2000 using WEBrick
#!/usr/bin/ruby
#---
# Excerpted from "Programming Ruby 1.9",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose.
# Visit http://www.pragmaticprogrammer.com/titles/ruby3 for more book information.
#---
require 'webrick'
include WEBrick
s = HTTPServer.new(Port: 2000,DocumentRoot: File.join(Dir.pwd, "/html"))
trap("INT") { s.shutdown }
s.start
@mattstifanelli
Copy link
Author

The first line " #!/usr/bin/ruby " assumes that the script is in the doument root and tell Unix to execute the file as Ruby ( The file will be executed by ruby because Unix can find the compiler(?) in that path )
But how can the ERB file (https://gist.github.com/968621) find the Ruby compiler(?) to be executed? Do I have to set something in the web server (WEBrick)? How does WEBrick find the path to the ruby compiler?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment