Making Ruby into PHP, Take Two

This page was written in response to Christopher Cyll’s Making Ruby into PHP. There’s a slightly more elegant way to do the the same thing:

bin/rubyhp

#!/usr/bin/env ruby

require "cgi" 
require "erb" 

cgi = CGI.new

print CGI.header
print ERB.new(ARGF.read).result(binding)

The Script

#!/usr/bin/env rubyhp

<!-- Your HTML and eRuby code here -->

Exception Handling

A slightly more advanced version that captures exceptions and returns information about them is available here:

rubyhp.rb

Note

This code is of course just for learning and not any serious use. I recommend you to base any Ruby web application on Rack.