Learning Ruby – Day 7

Day 7, playing catch-up.

I’m continually impressed with how concise the Ruby language is. As I mentioned in Day 4, Ruby frowns upon loops. I’m getting the impression Ruby also frowns upon taking up 2 or more lines to describe an action. Slagell’s examples of doing something a traditional way take up multiple lines, his here’s-a-better-way examples are single line. If we compare writing code to writing words and say each a chunk of code is a paragraph and each line of code is a sentence. Writing Ruby is more like dialog than narrative.

Note to self:
In Ruby, double quotes acknowledges backslash-escaped characters, i.e. "n" = new line. Single quotes will not, i.e. 'n' = n. Same is true for evaluating expressions within #{...}

Two Cool Things in Ruby:

  1. Chained Assigment
    Want to give a number of variables the same value?
    DaveSpeaks = JoeSpeaks = KatSpeaks = FrankSpeaks = "English"
  2. Multiple Assignment
    Want to quickly set the values of multiple variables at the same time?
    DaveSpeaks, JoeSpeaks, KatSpeaks = "English", "Dutch", "German"

The start of the day has quite a bit on binary numbers. I’m not sure when binary arithmetic will come in handy (a position I also expressed regarding Jr. High Algebra) but it’s nice to know it’s here when the need arises. The example Slagell offers at the chapter end feels like a band-aid for a poorly designed system. If any of you following along can provide a comment on when it’s beneficial to use binary arithmetric, I’d be extremely grateful.

As I finished up today’s exercises, Bic Runga’s ‘Listening for the Weather’ came through my iTunes. What an excellent way to wrap up Day 7.


This post documents my journey through Sam’s Teach Yourself Ruby in 21 days. I’ll be joining Al Abut in his effort to learn Ruby and blog along the way.