Sunday, February 25, 2007

So, you've developed a Ruby script or application for Windows. You'd like to compile the application into a portable executable file (EXE) that you can easily provide to your users without requiring them to install Ruby and the required libraries. Reach for RubyScript2Exe, Erik Veenstra's Ruby compiler. RubyScript2Exe traces and gathers all the necessary files, including the Ruby interpreter, and 'compiles' them into a single EXE file. You can easily embed images and icon files, and DLLs such as SQLite. RubyScript2Exe is easy to configure, very reliable, and well-documented and supported by the author. Executable files are 3-4mb in size for a typical wxRuby (0.6) application.

UPDATE: I have posted a new article with further details on using RubyScript2Exe, here.

To make compiling your Ruby apps even easier, install LopeSoft's free File Menu Tools and add a new file menu command for RubyScript2Exe. Then just right-click on your Ruby script in Windows explorer and select 'Compile with RubyScript2Exe'.

Speaking of compiling Ruby apps on Windows, keep an eye on the Gardens Point Ruby.NET Compiler project at Australia's Queensland University of Technology. I haven't done much with it yet but it looks promising.

Saturday, February 17, 2007

Need to output data to an Excel-compatible file -- but don't need to do any formatting of the resulting worksheet? You could simply write the data to a tab-delimited text file and give it the ".xls" filename extension...

There are, of course, several alternatives involving CSV, XML, or WIN32OLE. Sometimes I will output the data to a tab-delimited text file, then use WIN32OLE to open the file in Excel, apply formatting, and then save in native Excel format...

Friday, February 16, 2007

Many developers looking to take up Ruby on MS Windows have experience with Visual Basic, VBA and VBScript. There are millions of examples of VB code out there, and these can help you get up to speed with Ruby, especially in areas such as Microsoft Office automation. Here are a few tips when moving from VB to Ruby:

Require the win32ole library at the top of your script.

VB requires the Set statement when binding an object to a variable; Ruby does not.

In place of VB's CreateObject function, use Ruby's WIN32OLE.new method.

In place of VB's GetObject function, use Ruby's WIN32OLE.connect method to connect to an existing instance of an object.