Quick Tip: Getting Started with Ruby on Windows
From Aventine Solutions
I highly recommend installing Cygwin if you want to try some Ruby programming on Windows (see my notes on the minimum install if you're not already using it). Try out your favorite shell (or start with bash if you're not sure yet) and see that you have some kind of environment. Here a shot of the Cygwin install to help:
Cygwin will install Ruby in a likely place which is available already from the default environment:
% which ruby /usr/bin/ruby % ruby --version ruby 1.8.7 (2008-06-20 patchlevel 22) [i386-cygwin]
 Alternative: Standalone Installer
Lot's of Windows users dislike Cygwin and reasonably so when you look at the enormous number of files that get installed into the Cygwin home directory. If you're one of these (there 's no accounting for taste), then just use the standalone installer from this download page and run it.
Because I use Cygwin to begin with, I didn't like this approach as I then had to fix my shell environment to find the executables.
It's a must to install Rubygems because I recommend using external tools from there right from the start, especially rake. Also, Rails packages will require the gem installer.
Download the latest archive, then, from the command line, unzip the file into a staging area (this example assumes that I've installed the zip command line utilities from Cygwin beforehand) and install the gems package:
% cd /cygdrive/h/User/staging % unzip rubygems-1.2.0.zip % cd rubygems-1.2.0 % ruby setup.rb % which gem /usr/bin/gem % gem --version 1.2.0
If you're behind a proxy, then see Quick Tip: Developer's Environment Behind a Proxy#Rubygems.
I like to install rake right away for a couple of reasons. First, with a very small learning curve, you can make your very first Ruby scripts easily configurable and deployable. Second, rake is a classic first example of how Ruby can create domain specific programming languages, so it is good lesson there for newbies.
If your gem installer is working, simply do ...
% gem install rake % rake --version rake, version 0.8.1
I'm currently bitten by the proxy with NTLM authentication gotcha with the workstation I'm sitting at now, so gem cannot install packages from outside the firewall. Therefore, I'm forced to manually install this gem after downloading from the Rubyforge site:
% cd /cygdrive/h/User/staging % unzip rake-0.8.1.zip % cd rake-0.8.1 % ruby install.rb % which rake /usr/bin/rake % rake --version rake, version 0.8.1
 Ruby on Rails
Some of you will want to dive right into Ruby on Rails which I think is a perfectly good way to learn Ruby. You'll have to backtrack on certain syntax contructs to understand why things are magically working so well in your first Rails app, but, why not?
% gem install rails --include-dependencies
If you're taking this approach, you'll need at least a MySQL server instance running somwhere, but, then you probably already know plenty about that, hence your interest in Rails.
To start your new Rails app now, just do ...
% rails path/to/your/new/application % cd path/to/your/new/application % ruby script/server
This is all simply pilfered from Get Ruby on Rails in No Time.
That's it. Start coding.
irb is the interactive command line interpreter for Ruby and a great way to try things out, for example:
% irb irb(main):001:0> methods => ["inspect", "bindings", "tap", "popb", "display", "clone", "chws", "public", "irb_kill", "install_alias_method", "public_methods", "__send__", "irb_push_binding", "pwws", "instance_variable_defined?", "context", ...] irb(main):002:0> s = String.new "Hello World" => "Hello World"
 Other Tips
- if you are coming from the Java world, you'll find the striking difference to Ruby is the duck typing rather than the strong typing of Java. Also, Ruby uses closures rather than the anonymous classes of Java; the former very powerful construct is used all the time in Ruby whereas the latter is reserved for special application in Java due to it's limited usefulness (who can forget the instant headache brought on by the AWT ActionListener interface?). Get your head around these concepts first.
- Eclipse users might want to try installing the Ruby Development Tool for Eclipse to help with syntax highlighting, code formatting and regular expression testing. I still go to the command line to test scripts and try things out in irb, however. For Rails, I have yet to give RADRails for Eclipse my full attention due to a somewhat regrettable detour to IntelliJ, but this is on my todo list.
- if you are coming from the Perl and/or PHP world, you'll just need to know that everything is an object in Ruby from the start (as soon as you start typing, you are inside the Kernel object). Writing my first scripts, I sometimes struggled because of my recent Java history, but realizing that the language was originally conceived as a successor to Perl, things got a little easier. Perl programmers will recognize the ability to define dollar-sign globals and that regular expressions are first class objects like strings.
 Learning Resources
- Why's (poignant) Guide to Ruby by whytheluckystiff an entertaining and bizaar place to start, get hyped up on the zen of Ruby syntax. If Ruby closures are starting to give you a headache, you can easily detour to whytheluckystiff's quiet photo blog to escape this bitter reality.
- ruby-doc.org Home base for Ruby documentation
- Using the Rake Build Language by Martin Fowler
- Ruby on Rails Rake Tutorial (a.k.a. How Rake Turned Me into an Acoholic) by Gregg Pollack
- Closure as defined by Martin Fowler
- Ruby on Rails podcast usually hosted by Geoffrey Grosenbach, let's you hear about lot's of interesting things people are doing with Rails
- Get Ruby on Rails In No Time is the quick summary of getting your first Rails application up in 5 minutes.
Ruby being the kind of programming language it is, it makes perfect sense that the Programatic Programmer publishers have some very good books for learners:
- Programming Ruby, the Pragmatic Programmers Guide a must
- Rails for Java Developers does a nice job explaining Rails when you're used to J2EE
Other O'Reilly books I have on my bookshelf are