the blog
Back to -Blog

Ruby In Chrome

Making the Pascal connection...
by Huw Collingbourne
Tuesday 17 July 2007.

Programming languages with a ‘C-like syntax’ are undeniably widespread (C++, C#, Java, Perl, PHP et al) but, thank Heaven, there are still a few pleasantly eccentric programming language that refuse to follow the C-style orthodoxy. Ruby, of course, is one such language. And Pascal is another...


The front-end, seen here, is designed in Chrome. This communicates with the back-end - which is a Ruby program.

To my mind, Pascal feels like a nice ‘fit’ with Ruby. With its clear syntax and its moderate use of curly brackets (in Pascal they are used as comment delimiters), Pascal code can, at first glance, look quite similar to Ruby. There are, of course, huge differences - Pascal is a compiled language in which type declarations are obligatory and objects are only duck-typed if their type is declared as Duck! Nevertheless, when doing mixed language programming, switching to Ruby from Pascal is (in my experience) considerably less of a wrench than switching from C#.

RemObjects has a nice .NET implementation of Object Pascal called Chrome. Just like C# or VB, Chrome lets you design and debug your applications in Visual Studio and compiles them to the CLR. As I’ve explained before, I have already used our (‘in development’) Ruby Connector to create C#/Ruby and VB/Ruby projects, I couldn’t resist the temptation to take it for a whirl in Chrome too. As Chrome is a third-party (i.e. non-Microsoft) language, Chrome also provided me with the ideal opportunity to verify that the Ruby Connector really is as ‘language agnostic’ (on the .NET side of the connection) as it’s intended to be.

Chrome attaches event-handlers to the buttons which send messages to my Ruby program (part of which is seen in the window below)...

I am pleased to report that everything went remarkably smoothly. I designed a form in Chrome, dropped a Ruby Connector component onto it, set a few properties in the Properties panel to establish a connection between Chrome and Ruby, and then just coded the ‘front end’ application in Object Pascal. The Chrome code sends messages to Ruby via the Ruby Connector and Ruby then sends back replies to Chrome.

My test application was a simple CD database - entirely written in Ruby - which manages lists of mixed object types (defined by the base CD class and its two descendent classes, ClassicalCD and PopCD). The Ruby code contains methods to save and load the data to and from disk (in YAML format), go to the first CD, the last CD or a CD at a specific position, as well as create and add new CD objects or delete a chosen CD object.

...Ruby executes some code (as instructed by the messages which were sent to it) and Chrome displays Ruby’s replies on the form .

My Chrome application sends a message to Ruby when a button is clicked (a message may be something as simple as a Ruby method name with zero or more arguments) and it parses out and displays the data (the fields of each CD record) that Ruby returns to it. I originally wrote this as a C# application but it was very easy to translate into Chrome. I must say it was refreshing to write the .NET side of the application in Object Pascal.


The Ruby Connector will be provided as part of Ruby In Steel 1.2 later in the year (this will be available as a free update to registered users of RiS Developer). Meanwhile, if you feel a hankering to write .NET applications in Pascal, Chrome 1.5 is available from RemObjects on: http://www.chromesville.com/.

Bookmark and Share   Keywords:  development
  • Mixing Ruby and Chrome
    17 July 2007, by marc hoffman

    Huw Collingbourne just published an article showing how he integrated a Ruby back-end written in their excellent Ruby In Steel product with a Windows Forms front-end written in Chrome.

© SapphireSteel Software 2014