Installing JRuby in a Windows Environment

Education, Programming No Comments

I just installed JRuby on my Windoze XP box and thought I would share my experience for anyone interested in doing the same. It’s pretty straight forward, unless you know nothing of setting path variables in Windoze.

First, you’ve got to download JRuby (I got it from the jruby codehaus repository) and uncompress it into your choice of location. I grabbed the 1.1.2 binary tarball.

Next, you need to make sure you have a compatible Java runtime environment (JRE) or Java development kit (JDK) installed. If you don’t have one already, you can get these from the Sun Java site. You’ll notice the ‘Popular Downloads’ menu on the right has what you need. I already had this installed for my NetBeans installation.

Now comes the fun part. Make a note of the path to the JRE or JDK directory, as well as the path to your JRuby directory. I chose to install these as follows:

  • JDK: D:\programs\Java\jdk1.6.0_06
  • JRuby: D:\jruby-1.1.2

We’re nearly there! Next, just follow along:

  1. Right click on “My Computer” and select ‘Properties’.
  2. Choose the ‘Advanced’ tab at the top.
  3. Click on the ‘Environment Variables’ button near the bottom.
  4. Click the ‘New’ button under the ‘User variables’ section.
  5. For ‘Variable name’, put JAVA_HOME and for Variable value, put the path to your java install directory. Click the ‘OK’ button.
  6. Again, click on the ‘Environment Variables’ button near the bottom.
  7. For Variable name, put JRUBY_HOME and for Environment variable, put the path to your JRuby install directory. Click the ‘OK’ button.
  8. Select your PATH variable and click on the ‘Edit’ button.
  9. If the ‘Variable value’ field is empty, put your JRuby install directory’s path followed by \bin (mine: D:\jruby-1.1.2\bin)
  10. If the ‘Variable value’ field is not empty, put a semi-colon followed by your JRuby install directory’s path followed by \bin (mine: D:\jruby-1.1.2\bin)
  11. Click on the ‘OK’ button then click on the ‘OK’ button then click on the ‘OK’ button to get out of all this mess. tongueout

Finally, open a command prompt, type ‘jruby -v’ and hit return!

I tried to be as verbose and explicit as I thought possibly necessary in these directions. If I missed something or messed something up, please post to let me know and I will change or add to it right away.

Modulus as Handled by Ruby

Education, Programming 2 Comments

This is an explanation I gave to a student in class today of how the modulus operator behaves in Ruby. As I was writing the explanation down, it all became quite clear to me. I only had a tentative grasp on this concept until trying to explain it. That’s a good feeling when your helping another to understand something gives you clarity on the subject.

Given (-n % x) or (n % -x), the RHS (right hand side) of the modulus operation must be multiplied by the negative integer closest to 0 that will get it past the number on the LHS (left hand side). Then, the result is the difference between this number and the LHS. e.g.:

-7 % 3   # result is 2
# climbing (positive) from -9 (3 * -3) to -7

7 % -3   # result is -2
# dropping (negative) from 9 (-3 * -3) to 7

Of course, when the polarity is the same on both sides, such as (n % x) or (-n % -x), you just multiply the RHS times the positive integer that gets you the closest to the RHS without going past it then the result is the difference between the remainder and the LHS. e.g.:

7 % 3    # result is 1
# climbing (positive) from 6 (3 * 2) to 7

-7 % -3  # result is -1
# dropping (negative) from -6 (-3 * 2) to -7

It might help to note that in Ruby, the RHS always dictates the polarity of the result.