Writers

The Nerdary

Finally, a place where web developers blog.

Learning Ruby for Programmers

By Kenny Meyers September, 1st 2010

I’ve been using Ruby Koans to gain deeper knowledge about Ruby. I think this is one of the best setups for learning if you’re an experienced programmer (or you think of yourself as an experienced programmer, like me, which means terrible programmer in reality).

The general premise is based on another concept that was foreign to me: tests. You run the main ruby file path_to_enlightenment.rb which gives you feedback on which tests passed and which tests failed. It looks like this:

Thinking AboutAsserts
  test_assert_truth has expanded your awareness.
  test_assert_with_message has expanded your awareness.
  test_assert_equality has expanded your awareness.
  test_a_better_way_of_asserting_equality has expanded your awareness.
  test_fill_in_values has expanded your awareness.

Thinking AboutNil
  test_nil_is_an_object has expanded your awareness.
  test_you_dont_get_null_pointer_errors_when_calling_methods_on_nil has expanded your awareness.
  test_nil_has_a_few_methods_defined_on_it has expanded your awareness.

Thinking AboutArrays
  test_creating_arrays has expanded your awareness.
  test_array_literals has expanded your awareness.
  test_accessing_array_elements has expanded your awareness.
  test_slicing_arrays has expanded your awareness.
  test_arrays_and_ranges has expanded your awareness.
  test_slicing_with_ranges has expanded your awareness.
  test_pushing_and_popping_arrays has expanded your awareness.
  test_shifting_arrays has expanded your awareness.

Thinking AboutArrayAssignment
  test_non_parallel_assignment has expanded your awareness.
  test_parallel_assignments has expanded your awareness.
  test_parallel_assignments_with_extra_values has expanded your awareness.
  test_parallel_assignments_with_extra_variables has expanded your awareness.
  test_parallel_assignements_with_subarrays has expanded your awareness.
  test_parallel_assignment_with_one_variable has damaged your karma.

Then, you go to a specific file or “section” and make the test pass by filling in the correct value. The questions are centered around the concepts of hte language (arrays, strings, assignment, etc.) and Koans features a lot of Ruby’s quirky-sexy-fun too.

Test-driven learning is what makes it for programmers and not for pure beginners. Without some exposure to the idea of tests in programming I imagine it’s extremely weird to figure out what’s going on. It helps me, however, because I’m new to writing tests and seeing how they’ve built theirs in this simple tutorial helps me understand how to create mine.

I highly recommend it, and I don’t em adverbs often.

For absolutely pure beginners trying to learn a language like Ruby I suggest either Learn to Program for Ruby or Learn Python the Hard Way for Python.

Bookmark and Share

Comments

How boring. No comments. Add some fun below.

Post a Comment