News » 13 July 2009

Ajm Objects 0.8.8 Has Ruby 1.9 Support

I released a new version of ajm objects: 0.8.8 (don't ask me where these numbers come from, they don't mean anything). This is pretty much just a minor maintenance release.

The biggest change, which a few people have requested, is Ruby 1.9 support. I haven't kept up with JRuby updates (more on that in a bit), so this is a pretty big jump from JRuby 1.1.5 to JRuby 1.3.1. There have been too many changes for me to detail here, but in general every release of JRuby is faster, more efficient, and has more solid support for the Ruby language. They still don't claim to have full 1.9 support, but a lot of that work has been completed so I decided my ajm.ruby object for Max could have the option of running in Ruby 1.9 mode.

Supporting Ruby 1.8 and 1.9 presents a bit of a backward compatibility hurdle. It wasn't feasible for me to have 1.8 and 1.9 running side by side in a single Max session, so there is an all-or-nothing switch. As detailed in the Notes.txt, you just need to edit the ajm.ruby.properties file (found under Cycling '74/java/lib after properly installing ajm objects) and change this line: ruby.version = RUBY1_8 to this: ruby.version = RUBY1_9 Then restart Max and the ajm.ruby help file should indicate it is running a Ruby 1.9 compatible interpreter.

If you want to share patches using ajm.ruby and you are working with Ruby 1.9, keep in mind Ruby 1.8 is still the default for ajm objects. Eventually (sometime in 2010?) I expect to make Ruby 1.9 the default. So f you are writing any Ruby 1.8 code that you want to continue using in the future, it wouldn't be a bad idea to make sure it also runs with Ruby 1.9. This is not always a trivial thing as a couple of libraries have disappeared (I used to have an example in the help file using Generators, but this library has been removed in favor of Fibers in 1.9) or moved around (Complex is now part of the standard library and should not be imported with 'require').

Speaking of backward compatibility hurdles, one reason I haven't kept up with JRuby releases is due to its behavior for locally scoped variables across separate evaluations. Early JRuby versions remembered local variables, so sending snippets of Ruby code to ajm.ruby felt much like an irb (interactive ruby) session. Somewhere along the lines this behavior disappeared, perhaps for performance reasons on web servers, and I did my best to patch JRuby and maintain this behavior because I felt it was in line with the Max mentality to allow for these kinds of interactive scripting sessions.

I know I am sometimes anal about these things, and decided it was a dumb reason to not try to stay up to date with JRuby. So not if you are sending separate Max messages to ajm.ruby, and you want to remember a variable, you should make it a $global $variable (by putting a '$' in front of the name). The help file examples have been updated to reflect this new usage. I think this isn't that big a deal in practice, because I also end up using separate script files when writing any non-trivial logic for ajm.ruby. Apologies if this breaks anyone's patch!