learn_ruby

<title>Test-First Teaching: learn_ruby: learn_ruby</title>

the home of test-first teaching

Labs:
  • 00 Hello
  • 01 Temperature
  • 02 Calculator
  • 03 Simon Says
  • 04 Pig Latin
  • 05 Silly Blocks
  • 06 Performance Monitor
  • 07 Hello Friend
  • 08 Temperature Object
  • 09 Book Titles
  • 10 Timer
  • 11 Dictionary
  • 12 Rpn Calculator
  • 13 Xml Document
  • 14 Array Extensions
  • 15 In Words

learn_ruby

Learn Ruby Test-First

Setup

  • Install Ruby

    • You will need Ruby, RubyGems and RSpec to Learn Ruby.
    • We recommend using rvm but you can use any Ruby you want. We officially support Ruby 1.9 but probably work with 1.8.7 as well.
    • Here are some good instructions for installing the required software.
    • Here are some other good instructions, using rvm.
  • Open a terminal window. (On Mac OS X you can use the Terminal app.)

  • Install RSpec

      gem install rspec
    
  • Enter the course directory. (That's the same directory that this index.html file is in.)

      cd learn_ruby
    
  • Enter the 00_hello lab.

      cd 00_hello
    
  • Open the lab's index.html file in a web browser and follow the instructions there.

      open index.html  # this works on Mac OS X only!
    

Using These Exercises

Your course directory has a list of lab directories. Each directory has a spec file. You will write all the code to make all the specs in it pass.

To get your feet wet in this process, go into the "hello" lab with cd 00_hello and read the detailed instructions in its index.html file.

If you got through "hello", then congratulations! Now it's time to go to the next directory (whose name begins with 01_) and start learning Ruby!

Course Outline

Each course is different, so check with your instructor for details on the curriculum he or she has chosen. Here is a survey of a few of the labs:

  • hello Gives you a feel for how to use these tests. See 00_hello/index.html for detailed instructions.
  • temperature Write and class and do some basic math.
  • calculator introduces a little more math, and you'll need to iterate.
  • pig_latin lets you manipulate strings.
  • in_words asks a number to say itself in English. Extend a built-in class. By the end you'll use conditionals, arrays, iteration, and maybe even some recursion.
  • blocks introduces block syntax, including yield

Advanced Setup

After you're in the swing of things, you can read about advanced setup techniques like pulling changes and forking. But don't worry about it at first.

Problems? Questions?

First, ask your neighbor. Then, ask your instructor.

Then ask Google (seriously!). If there's an error, try copying the error string and pasting it into a Google search box. If that doesn't help, do a search on one of these sites:

You can also find help at the TestFirst.org site or the Test-First Teaching mailing list.

Remember, if you post a technical question online, you should

  1. Include version numbers:

     $ ruby -v
     ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0]
    
  2. Note where you have already looked for an answer

  3. If you can, include code snippets that reproduce the problem in isolation

Resources

Here is a broad survey of many resources you may find useful. Don't try to read them all! Just browse around when you feel like learning more about Ruby.

Learning Ruby via Tests (and/or Interactively)

Learning Ruby and Programming

Test-Driven Development

Online Ruby References

Other good resources

Credits

  • Concept by Alex Chaffee
  • Exercises by Alex Chaffee, Sarah Allen, Liah Hansen, Kai Middleton
  • Early quality assurance by Sumiki, Dimitri, Liah, Michael, and Brendan
TestFirst.org