Reinforcing Ruby

Now that I’ve made it through the Codecademy Ruby track, I’ve started reading Chris Pine’s Learn to Program (2nd edition). I think this is a great resource. It’s a bit more in-depth than the Codecademy track, and I think I’m getting more out of it now that I know a bit of Ruby. For example, previously I didn’t really understand why we used the .chomp method after gets. (To get rid of extra white space. Okay, great. Whatever.) Pine explained through example that gets captures all of the characters you type in – including the Enter keystroke that submits what you type. That’s why you end up with all the extra white space, and why .chomp is so useful.

I also started going through the Treehouse videos and quizzes on Ruby. The Treehouse material is a bit slower paced and can be harder to get through because of this. I’ve been downloading the videos and watching them at an accelerated pace, which helps a lot. Treehouse seems to be trying to give a broad, general overview, but a few times I’ve found them give a quick two-minute introduction to something and then say “check the Ruby docs for more before fully explaining the use of something. They do go through various parts of the Language and clearly lay out a lot of the methods and operators for each section. I’ve been writing them down to further reinforce them, and sometimes new ones come up. For example, in the example:

a = 1
b = 1.0
a == b
=> true
=> false

a.eql?(b) is checking to see if a and b are of the same value and type. Similar to the === in javascript.

A few things I learned (or had my memory refreshed on) today:

  • Escaping characters is a way to write certain characters, like new line, ‘, “, tab, and \ in a string. I learned this a long time ago, but it hadn’t come up for a while so the refresher was good.
  • << can be used as a concatenation operator, instead of +. I've become a fan of string interpolation, so I don't know how much I'll use this, but it's good to know.
  • Speaking of string interpolation, today I found out that it only works inside strings that start and end with double quotes! Very good to know!
  • I learned more about floating point math, and the rounding errors that usually come about if you use it. Treehouse taught about a “bigdecimal” library which allows you to do floating point math accurately.
  • I learned how to install gems. It’s so easy! You just have to type into the terminal “gem install gem_name_here”
  • Arrays have intersection operators that return all values that are common between the two arrays.
  • The window is an object, called “main”

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>