Bye perl, hello ruby

Today I was thinking about changing my VPS to run on a pure ruby platform rather than the pure perl platform I currently have setup.

When I say “pure” I dont that in a strict sense, in fact I don’t mean pure at all, I just mean that I use as much Perl as possible.. and that I want to swap out the Perl parts for Ruby bits.

So first port of call is web services .. for Perl we have Plack in Ruby there is Rack .. so first of all lets get a very simple rack app started by putting the following in a file called ‘Rakefile’

require 'rack'
class TryRack
    def call(env)
        [200, {"Content-Type" => "text/plain"}, ["Hello world!"]]
    end
end
Rack::Handler::WEBrick.run( TryRack.new, :Port => 9000 )

Then I just run: rake

“Roberts ya muvas bruva”, rack app is running :)

rackup the lines

Althou the rake task does work, rackup is the perfered way to get rack apps running, so lets creating a file ‘tryrack.ru’, with following content:

class TryRack
  def call(env)
    return [ 200, {'Content-Type' => 'text/html'}, ["clay finger!"] ]
  end
end
run TryRack.new 

Now I just run: rakeup tryrack.ru