Hello world/Web server: Difference between revisions

Added example with tap method.
No edit summary
(Added example with tap method.)
Line 1,263:
trap("INT") {server.shutdown}
server.start</lang>
 
Same code without <code>trap</code>, in a single statement using <code>tap</code>.
<lang Ruby>require 'webrick'
WEBrick::HTTPServer.new(:Port => 80).tap {|srv|
srv.mount_proc('/') {|request, response| response.body = "Goodbye, World!"}
}.start</lang>
 
Using the [http://www.sinatrarb.com/ sinatra] gem:
<lang ruby>require 'sinatra'