Course List >> Web Development 101 >> The Back End >> 2: Ruby Basics
Scroll up or hover over the breadcrumbs to view the navigation bar

Ruby 101

Our back end focus will be on Ruby, the language designed for programmer happiness. What takes dozens of lines of code in Java or a hundred in C could take just a couple in Ruby because it prepackages lots of sneaky functions into easy-to-use convenience methods.

Ruby is pretty darn close to Python. In some ways, they sort of resemble romance languages -- once you've learned one, it's not terribly hard to pick up another because they tend to follow many of the same conventions, just using different "words". Python tends to be taught more in colleges and is used a fair bit for more data-intensive and processor-heavy applications.

But Ruby has a secret weapon that makes it the love of fast-iterating website producers -- the framework Ruby on Rails (which we'll cover in the next section on Frameworks). It has been optimized for being able to write code faster and with less headache, which allows you to iterate more frequently when building a website. By so doing, the end product is more likely to suit the client or the user's needs, making your first mission as an engineer a success.

With either of the languages, there are a couple of things that aren't immediately intuitive but become very useful when you understand them. These are the quirks and nifty tricks that you didn't see in Javascript.

In this lesson we'll do a healthy introduction to Ruby and then, later on in the full Ruby course, you'll get to understand it like the back of your hand.

A final note -- you'll be learning a bunch of new terminology and concepts here but don't think they're only applicable to Ruby. Most of it (like methods, classes, objects etc.) will pop up again in pretty much any other language you ever pick up.

Points to Ponder

Look through these now and then use them to test yourself after doing the assignment

  • What is an "interpreted" language?
  • What is IRB?
  • What are Objects?
  • What are Methods?
  • What are Classes?
  • What are Blocks?
  • What is an Array?
  • What is an Iterator?
  • What are hashes?
  • What is a library?
  • What is a gem?

Assignment:

  1. Go to tryruby.org and do the quick exercises there to get your feet wet. Don't worry about the stuff where they're reading from a file, that's getting deeper than you need to right now.
  2. Read through the Ruby in 100 Minutes project from Jumpstart Lab. If you can't get IRB running, check out the Installations Project, which you should have done already.
  3. Dive in a little deeper by reading chapters 1-10 of Chris Pine's Learn to Program. Try to do the exercises at the end of each chapter. Take a crack at chapter 10, but don't feel disheartened if it still doesn't click for you. Answers to the exercises are available at learntoprogramanswers.blogspot.com

Bonus Assignment:

Redo the same Project Euler problem that you previously did in Javascript but using Ruby instead (try using IRB or a .rb file that you run from the command line by using $ ruby ./yourfilename.rb):

Have a go at the next two problems too; feel free to move on to the next lesson though if you find it too challenging. The aim here is to increase your resilience to difficult problems and get you more exposed to how loops and methods are structured:

Additional Resources

This section contains helpful links to other content. It isn't required, so consider it supplemental for if you need to dive deeper into something

From the creators of The Odin Project...

The Viking Code School
Viking ad 180x150