Better API with Ruby

I was building an API to automate MS Access and started with VBScript, because I tough it would be more simple. Even with no built-in include support, no true test framework, the code was pretty simple. The problem emerged at the time of using the resulting API…

VBScript:

GetControl(GetForm(myApp, "Contact"), "Name").Value = "test"

= ugly

Now with the help of ruby win32ole module and some magic…

Ruby:

my_app.contact.name = "test"

= beautiful

If you haven’t given ruby a try yet, I suggest you do ASAP with anything: test, build script, code generation, just one time and I guaranty you’ll be amazed.

3 Comments

Filed under ruby

3 responses to “Better API with Ruby

  1. How’d you do that with Ruby? be interested in seeing what WinAPI calls you are making here or is it simply a wrapper youve written in Ruby

  2. I can’t give you the whole code but it’s more like a wrapper to win Access ole object. Here’s a little hint:

    require 'win32ole'
    access = WIN32OLE.new('Access.Application')
    access.OpenCurrentDatabase('...\funky.mdb')
    ctrl = access.Forms[0].Controls[0]
    puts "#{ctrl.Name} = #{ctrl.Value}"

  3. Thanks Marc-Andre, thats quite clever its similar to what I need to do except I will probably have to make mine more generic using FindWindow() calls etc

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s