January 2007 Archives

Local variable assertion in Ruby

| 5 Comments

I'm just starting with Ruby, but one of the tricky parts of this language is that since it has no way to declare a variable, you can't tell it that you want a variable to be local. When you assign a value to a variable, you will be using a variable from a containing scope, if any such variable exists. And if no such variable exists, then you'll be creating a new one in the local scope. Block parameters also work this way, which is confusing.

I've attempted to create a workaround. My local() method asserts that the named variables do not yet exist, guaranteeing that any uses that follow will create local variables instead of clobbering existing variables. My code is in the extended entry. See the introductory comment for usage information.

I don't have enough Ruby experience yet to know if this is actually something useful, or just a curiosity. Creating this function was an interesting exercise for me, so I haven't looked yet to see if something like this already exists.

Read on for the code...

Desolation Row Revisited

Jan Lewis has written and recorded a great version of Desolation Row well suited to current events. You can hear and watch at http://www.youtube.com/watch?v=MQNBJpapIpQ.

Jan says he's a Java programmer, which allows me to make the weak case that this post is appropriate on this blog. New blog editorial policy: I'll consider linking to war protest songs written, recorded, or even just submitted by Java and JavaScript programmers and their ilk! :-)

If you're not a Bob Dylan fan, you may not be able to fully appreciate Jan's song, but it is still good. See my last post from December 2006 for the lyrics to the first verse of the original

Jude 1.03

I've relased a new minor version of Jude. This one fixes a bug that prevented it from reading certain class files in Java 6. Download Jude 1.03. As always, you need a license to use Jude. You can request an evaluation license or purchase a license.

If you've got no idea what I'm talking about, you can read about Jude.

Books

Comprehensive coverage of Ruby 1.8 and 1.9

"The New Most Important Ruby Book"
Peter Cooper,
rubyinside.com

Completely updated for Ajax and Web 2.0

"A must-have reference"
Brendan Eich,
creator of JavaScript

The classic Java quick-reference