Day 14: Changing it Up for a Bit

I had thoughts all day about whether I should focus on Ruby for a bit or move on to the rest of the Ruby on Rails tutorial. I decided after some advice at the codenewbies Slack channel to hone my Ruby skills a bit more. Gregory Brown of made a good point that I could go through Zed Shaw’s highly recommended book Learn Ruby the Hard Way while using the other highly recommended book, Chris Pine’s Learn to Program for context. I decided to move ahead for a bit doing this.

So, I spent some time setting up Ruby on my computer, as well as tinkering in Power Shell. It has been a long time since I used Power Shell.

And then I started with Exercise One. One nice thing about getting through 4 chapters of the Rails tutorial is that I understand what I am doing here. So, Exercise 1: A Good First Program. I opened up Sublime (Mr. Shaw suggested Notepad ++ but I had Sublime installed prior and wanted to try it. I typed in the following:

Then went to Power Shell and ran this:

PS C:\ruby> ruby ex1.rb
Hello World!
Hello Again
I like typing this.
This is fun.
Yay! Printing!
I’d much rather you ‘not’.
I “said” do not touch this.
PS C:\ruby>

Right now I know the answer to Study Drill 3, and I may know the other two, but not sure. Number 3 talks about what happens if you put a hashtag at the front of the line. It comments the line out! I will come back to the Study Drill…

Exercise 2: Comments and Pound Characters

I typed in:

And got this:

PS C:\Users\Nick> cd\
PS C:\> cd ruby
PS C:\ruby> ruby ex2.rb
I could have code like this.
This will run.
PS C:\ruby>

Exercise 3: Numbers and Math

I will say that this tutorial has me typing a lot. I think this is good. Here is what I typed up for the exercise:

And the result once I ran it:

PS C:\ruby> ruby ex3.rb
I will now count my chickens:
Hens 30
Roosters 97
Is it true that 3 + 2 < 5 - 7? false What is 3 + 2? 5 What is 5 - 7? -2 Oh, that's why it's false. How about some more? Is it greater? true Is it greater or equal? true Is it less or equal? false PS C:\ruby>

OK, Study Drill. Zed is intense.

1. Above each line, use the # to write a comment to yourself explaining what the line does.

2. Remember in Exercise 0 when you started Ruby? Start Ruby this way again and using the math operators, use Ruby as a calculator.

OK< I know how to do this pretty easily. Example:

PS C:\ruby> 3 + 3
PS C:\ruby> 18 % 5

3. Find something you need to calculate and write a new .rb file that does it.

Hmm, ok I give in tonight. I will start here tomorrow.