…and you’ll be better than 99% of working programmers. At least, that’s what a recent digg article stated and then linked to this article. While I don’t really believe the numbers, I do believe that there are quite few “programmers” out there that do nothing but copy and paste code. But you and I won’t be one of those. We’ll walk through how to create this very simple (but maybe not for most?) program in Ruby. Let’s outline what it needs to accomplish:

This program, called FizzBuzz, needs to do the following for the numbers between 1 and 100: if the number is divisible by 5 and 3, print FizzBuzz. If the number is divisible by 5 only, print Fizz. If the number is divisible by 3 only, print Buzz. Otherwise, print the number itself. This reminds me of a drink…er…number game I used to play in college. Ok, so the hardest thing about writing this program is just understanding how the modulus operator works. Most languages have a mod command and in Ruby it happens to be %. The statement “x % y” would divide x by y and then return the remainder. So, to determine if a number is divisible by x, we check that when we mod it with x, the result is 0 (thus, no remainder). With this small piece of knowledge we can write the FizzBuzz program and break into the top 1% of programmers world-wide:

The Code

And that’s all there is to it. Ask any questions, otherwise enjoy and welcome to the top 1%.

Ok, so I know that there are other “getting started with rails” tutorials out there, but I thought I’d take a stab at it. I’m doing this from the “teach a 2 year old” point of view, so I’ll try to walk you through everything. And I’ll try to do it in 10 steps. Now, if you don’t know what Rails is, check out the rails website. Also, there is a solution out there called InstantRails for windows that will allow you to install rails from a single application. However, following the steps below will give you much greater flexibility in the future and you might actually learn something along the way! The goal is to end up with a rails development environment on your Windows box including ruby, rails, mysql (your database) and mogrel (your development web server). Don’t worry if you don’t know what these things are, just follow along. Here we go!

1. Download and install the ruby one-click installer.
2. Go to Start -> Run, type “cmd”. At the command line, type the following: gem update – -system (no space between the dashes, just for clarity’s sake).
3. Still at the command line, type: gem install rails – -include-dependencies (again, no spaces)
4. Again, at the command line type: gem install mongrel – -include-dependencies (do I have to say it again? no spaces)
5. Download and install MySql Server 5.0. Pick any mirror. Uncheck the option for changing the root password during the install. Make sure you check the option to run the service when you finish the installation.
6. Download and install HeidiSQL. This will let you view your MySQL database through a graphical user interface.
7. Create a database for our application. Start HeidiSQL, create a new connection, accept ALL the defaults (no password or anything else) and click connect. Create a new schema (right click on the left hand pane) named: myrailsapp_development. Exit the program.
8. Create your rails application. Go to Start -> Run. Type “cmd” and hit enter. At the command line, type: rails myrailsapp. Now, type: cd myrailsapp. You now have a new rails app and you are inside the directory!
9. Still at the command line type: ruby script/server. Your mongrel server is running!
10. Open up your internet browser and into the address bar type: http://localhost:3000. You’re rolling with rails! Yahoo!

Hope that all worked out for you! For more information, check out the rails website. There are also a ton of getting started tutorials out there and the rails site should point you to a lot of them. Good luck, and enjoy rails!