This post contains a cross platform Ruby method to return the total number of CPU cores. There are gems, such as facter, that will do the same thing and much more but if you just want a quick and dirty single purpose method this will probably suffice. The only tricky bit was picking the best way to do the determination in Windows. I ended up using a WMI approach described in Rick Minerich's There Counting Processors in .NET: The Pros and Cons of Five Different Methods post. Read the rest of this entry

In previous posts I've covered using multiruby to switch between Ruby 1.8 & 1.9 and how to add JRuby to your multiruby environment. This post describes using multiruby as a way to install and experiment with Rubinius in Mac OS X. Read the rest of this entry

In Switching Between Ruby 1.8 & 1.9 with multiruby I covered setting up and using Ruby 1.8 and 1.9 versions in multiruby. This post describes adding JRuby to the list of multiruby versions in Mac OS X. Read the rest of this entry

I just recently built and installed three different Ruby versions (see Installing Ruby 1.8.6, 1.8.7 and 1.9 on Leopard). Following that I wanted to do some benchmark testing between 1.8 and 1.9 on a separate project so I began to use ZenTest's multiruby. It worked great for the benchmarking and I started to think about how to use multiruby as a way to manage and switch between Ruby installations. As I started looking into it I came across Dr Nic's Future proofing your Ruby code. Ruby 1.9.1 is coming post, which turned on the rest of the lights for me. The Dr Nic post does a nice job of describing how to use multiruby including setting up specific Ruby versions, adding gem support and using it with sake tasks. I'll cover some of the same setup and usage information so that this post stands alone but I won't repeat it all so I recommend you read Dr Nic's post. In addition I'll provide information about how to overcome a RubyGems installation issue that I encountered and how to use the multiruby Ruby installations as a way to dynamically switch between Ruby versions. I'll also discuss how the static build and install from source approach used in Installing Ruby 1.8.6, 1.8.7 and 1.9 on Leopard could be modified to be provide a non-multiruby dependent way to do Ruby version switching. At the end of the post I'll mention using symlinks as an alternative and how that approach could be used with multiruby. Read the rest of this entry

Ruby provides several simple ways to launch subprocesses. Ruby's popen method comes into play in situations where cross platform handling of subprocess IO is required. Ruby also provides mechanisms to trap and send signals, such as the SYSINT (Control-C) signal. Putting popen and signal handling together to launch and manage a subprocess is straight forward but there's a limitation; popen lacks support for capturing standard error. By default standard error output is just displayed on the screen as if the subprocess was launched from the command line. There are a couple of workarounds available, in some cases it may be acceptable to discard standard error by redirecting it as part of the subprocess launch command, i.e. "command 2>/dev/null"; another, and typically better, option is to redirect standard error so that it's merged with standard output, i.e. "command 2>&1". Unfortunately the redirection impacts the Process ID (pid) for the launched subprocess, which breaks the simple standard signal handling that I mentioned earlier. In addition to the pid issue, getting the Control-C signalling support to work in Windows can be challenging. This post walks through an example that shows popen usage and how to send Control-C signals to a subprocess in Windows and Unix when standard error is redirected. It concludes with a brief discussion of popen3 and popen4 as alternatives to popen. Read the rest of this entry

Dec. 19, 2008 Update: This post covers setting up and switching the default Ruby installation in /usr/local. If you're looking for a more dynamic way to test and/or switch between Ruby versions see Switching Between Ruby 1.8 & 1.9 with multiruby.

I had originally installed Ruby 1.8.6 on Tiger from source using Dan Benjamin's Building Ruby, Rails, Subversion, Mongrel, and MySQL on Mac OS X instructions. I upgraded to Leopard but continued to run the /usr/local version of Ruby. It has been working fine for me but for various reasons I decided it was time to upgrade to 1.8.7. I was happy to see Dan had created updated instructions for Leopard in his Installing Ruby, Rubygems, Rails, and Mongrel on Mac OS X 10.5 (Leopard) post. So I decided that I'd just install over my 1.8.6 version. It didn't go off without a hitch, I ran into a problem compiling readline. This post documents what worked to resolve the problem, my journey back to 1.8.6, how to add 1.9 support and how to switch between versions. Read the rest of this entry