Building simplicidade.org: notes, projects, and occasional rants

Ruby and Cocoa

I woke up around 6:00 am (very early for Portuguese standards) and couldn’t get back to sleep.

I had been reading about Ruby on Rails and I was thinking about it, how it could affect some of my projects.

Yet, for some reason, I started thinking about Cocoa. I knew that there was a Ruby/Cocoa framework, and I have some experience with CamelBones, the Perl/Cocoa framework. How easy is to create a small Cocoa app in Ruby?

Well, check it out: a Web browser made in Ruby and Cocoa. It works for me, but I don’t know if all the frameworks where included.

It was my first Ruby program. Ever. An it was not a very big one:

require 'osx/cocoa'
require 'osx/webkit'

class AppController < OSX::NSObject
  include OSX

  ib_outlets :inputText, :previewWindow;

  def previewBtnClicked (sender)
    urlText = @inputText.stringValue
    url = NSURL.URLWithString(urlText);
    request = NSURLRequest.requestWithURL(url)
    @previewWindow.mainFrame.loadRequest(request)
  end
end

Anyway, I’ll do a short movie next week: How to build a web browser with Ruby in 20 minutes.