Q:

how to display ruby output in browser?

Am learning ruby scripting language. I was implementing exercises in ruby. 
In that I had a one problem. I need to display the ruby output in browser. 
For example, I have a one ruby script, named hello.rb. It will print the "Hello world message". Normally if we execute this with ruby interpreter it will print that in the terminal. I need to print that hello world message in the browser by invoking the ruby script. 
For that I was referred in the internet. In that they told that you need to install gem 'tilt'.
Without installing any gems how can we achieve this ?
Thanks in Advance!

A:

Ruby comes with a simple web server, webrick.  The following code uses webrick to implement a simple "hello, world" web server:'
require "webrick"

server = WEBrick::HTTPServer.new(Port: 8000)
server.mount_proc "/" do |req, res|
  res.body = "Hello, world!\n"
end
server.start

When run, it prints some log output to show that it is running and ready to serve requests:
[2016-07-22 12:02:01] INFO  WEBrick 1.3.1
[2016-07-22 12:02:01] INFO  ruby 2.3.1 (2016-04-26) [x86_64-linux]
[2016-07-22 12:02:01] INFO  WEBrick::HTTPServer#start: pid=16318 port=8000

I used the *nix utility curl to give the server a request:
wayne@treebeard:~$ curl localhost:8000
Hello, world!

Although I used curl, any web browser would also work.  After starting the program, send your web browser to:
http://localhost:8000

