Start and call Ruby HTTP server in the same script
问题 I wonder how I could start a Ruby Rack application (such as Sinatra) and call it with Net::HTTP or similar in the same script. Of couse I could do something like... require 'sinatra/base' require 'net/http' t = Thread.new do class App < Sinatra::Base get '/' do 'Hi!' end end App.run! :host => 'localhost', :port => 1234 end sleep 2 puts Net::HTTP.start('localhost', 1234) { |http| http.get('/') }.body t.join puts 'Bye!' ...but it doesn't feel optimal to sleep for two seconds, waiting for Thin