Day 33: Making the Decision to Write My First App

Well, I have made a decision. I will be writing my first app over the coming days (possibly weeks).

I have decided to make an app in Ruby to track books I have read or listened to. I would like to eventually be able to assign a short, one sentence review to each. I would also like to figure out a way to mark the books as read, listened to, or wish list. Let’s get started.

Preface: I will be borrowing code from previous exercises. I will make a lot of mistakes. I will not apologize for either. I will say thanks to the previous exercises, however.

OK, here goes. The first bit of my code adds a menu that barely works and allows me to add a book.

OK, this is what happens:

demosthenes131@book_tracker:~/workspace $ ruby book_tracker.rb
Select an option from the below choices
a: Add a Book
v: View the Books
s: Search the Books
e: Exit
a
Add a book!
Ender’s Game
Select an option from the below choices
a: Add a Book
v: View the Books
s: Search the Books
e: Exit
a
Add a book!
Old Yeller
Select an option from the below choices
a: Add a Book
v: View the Books
s: Search the Books
e: Exit

Weird. It won’t keep the previously entered book. I need to create an array to collect these, I’m guessing…

And I have banged my head for an hour on this. I scrapped the whole thing and went simple:

and the results:

demosthenes131@book_tracker:~/workspace $ ruby book_tracker.rb
Add a book!
Ender
[“Ender”]
Add a book!
Shadow
[“Ender”, “Shadow”]
Add a book!
Hitchhiker
[“Ender”, “Shadow”, “Hitchhiker”]
Add a book!
Dresden
[“Ender”, “Shadow”, “Hitchhiker”, “Dresden”]
Add a book!

OK, this works. Let’s go a little more fancy. I want it to loop until I end it, and allow me to enter as many books as I decide. When I end it, I want it to print the list of books and then break. I worked it out a bit:

book_list = []

and it works! I was as surprised as you are:

demosthenes131@book_tracker:~/workspace $ ruby test.rb
Do you want to add a book? (yes or no)
yes
Add a book!
Ender’s Game
Do you want to add a book? (yes or no)
yes
Add a book!
Dresden Files
Do you want to add a book? (yes or no)
yes
Add a book!
Hitchhiker’s Guide to the Galaxy
Do you want to add a book? (yes or no)
no
[“Ender’s Game”, “Dresden Files”, “Hitchhiker’s Guide to the Galaxy”]

I also want to be able to add a one sentence review. I think a hash would work for this. Here is my attempt:

And the results:

demosthenes131@book_tracker:~/workspace $ ruby test.rb
Do you want to add a book? (yes or no)
yes
Add a book!
Ender
How about a short, one sentence review? (yes or no)
yes
Add your review!
Great book!
Do you want to add a book? (yes or no)
yes
Add a book!
Dresden
How about a short, one sentence review? (yes or no)
yes
Add your review!
Lots of fun
Do you want to add a book? (yes or no)
no
[“Ender”, “Dresden”]
{“book”=>[[“Ender”, “Dresden”]], “review”=>[[“Great book!”, “Lots of fun”]]}

I tried to work out the way to display this right. No luck as of yet. My last update:

and the result:

demosthenes131@book_tracker:~/workspace $ ruby test.rb
Do you want to add a book? (yes or no)
yes
Add a book!
Ender
How about a short, one sentence review? (yes or no)
yes
Add your review!
Awesome book
Do you want to add a book? (yes or no)
yes
Add a book!
Dresden
How about a short, one sentence review? (yes or no)
yes
Add your review!
urban fantasy fun!
Do you want to add a book? (yes or no)
no
[“Ender”, “Dresden”]
{“book”=>[[“Ender”, “Dresden”]], “review”=>[[“Awesome book”, “urban fantasy fun!”]]}
book – [[“Ender”, “Dresden”]]
review – [[“Awesome book”, “urban fantasy fun!”]]

Day 33: Back to Learn Ruby the Hard Way (Part One)

I am back and learning Ruby the Hard Way. Let’s get to it. I am skipping ahead a bit as Exercise 36 was to work on a RPG game and Exercise 37 was memorizing symbols. I am working on a different project soon to add to my portfolio. I am also adding the symbols to AnkiDroid for study. So, I am doing Exercise 38: Doing Things to Arrays.

Here is the code we are starting with:

and the results:

demosthenes131@rails-tutorial:~/workspace/LRTHW (master) $ ruby ex38.rb
Wait there are not 10 things in that list. Let’s fix that.
Adding Boy
There are 7 items now.
Adding Girl
There are 8 items now.
Adding Banana
There are 9 items now.
Adding Corn
There are 10 items now.
There we go: [“Apples”, “Oranges”, “Crows”, “Telephone”, “Light”, “Sugar”, “Boy”, “Girl”, “Banana”, “Corn”].
Let’s do some things with stuff.
Oranges
Corn
Corn
Apples Oranges Crows Telephone Light Sugar Boy Girl Banana
Telephone#Light#Sugar

So, in this exercise we are seeing how to add items into the array, as well as count the items inside it.

Study Drill time:

1. Translate these two ways to view the function calls in English. For example, more_stuff.pop() reads as, “Call pop on more_stuff.” Meanwhile, pop(more_stuff) means, “Call pop with argument more_stuff.” Understand how they are really the same thing. and 2. Translate these two ways to view the function calls in English. For example, more_stuff.pop() reads as, “Call pop on more_stuff.” Meanwhile, pop(more_stuff) means, “Call pop with argument more_stuff.” Understand how they are really the same thing.

I am going to combine these. Let’s take a look:

Take the ten things and split them up with a space.

While the list of stuff is not 10, take items and add them until there are 10.

Let’s call things from the array in various ways:

The item at cardinal number 1 is Oranges.
The last item is Corn
Pop the last item of the array off, which is Corn.
Join all the items together using a space and list them here.
List the items at cardinal numbers 3 4 5 and join them with a #.

3. Go read about “object-oriented programming” online. Confused? I was too. Do not worry. You will learn enough to be dangerous, and you can slowly learn more later.

I decided to find a simple explanation for now. Take a look here.

4. Read up on what a “class” is in Ruby. Do not read about how other languages use the word “class.” That will only mess you up.

This was taught at length over at Treehouse!

5. Do not worry If you do not have any idea what I’m talking about. Programmers like to feel smart so they invented object-oriented programming, named it OOP, and then used it way too much. If you think that’s hard, you should try to use “functional programming.”

I enjoy this.

6. Find 10 examples of things in the real world that would fit in an array. Try writing some scripts to work with them.

Hmm. I mean, a lot of things can be used in an array. I will do one example as I worked with these at length at Treehouse.

and the result:

demosthenes131@rails-tutorial:~/workspace/LRTHW (master) $ ruby studydrill38.rb
The best breed of dog is the Jack Russell Terrier.
Jack Russell Terrier * Poodle * German Shepherd * Collie * Pug

OK, be back a little later.

Day 32: Finishing Ruby Track in Treehouse

I have a lofty goal today. I want to finish the Ruby track at Treehouse. I did work yesterday (which technically should be day 32) and completed the True and False video and quiz as well as the Nil video and challenge. I did these over my phone. That means I am starting on the Precedence video today. I am going to work hard and get through this. Let’s go:

and finish the quiz!

Continue reading

Day 31: A Quick Treehouse Dip

I didn’t get to come back yesterday, but getting a chance to do a small lesson today. I have family in and will being spending time with them.

First video: What is a Boolean value?

Which is a quick overview of Boolean values.

Challenge Task 1 of 2

Write an if statement that calls the flash_car_speed method if the car_speed variable is greater than the speed_limit variable.
Assume that the flash_car_speed and display_car_speed methods have been defined elsewhere.

Challenge Task 2 of 2

Add an else clause to the if statement which calls the display_car_speed method.

Oh. I did it already…

Challenge Task 1 of 1

Using the negation operator, reverse the logic in the boolean statement.

Day 30, Part 1: Continuing to Learn Ruby!

So, Friday and Saturday I have family coming to visit. I will try to study some, but I will probably have less time then usual. I have a lot to do today to prepare for the visit, but I am also committed to studying and transitioning to a web development career. Let’s get started at Treehouse:

I am in the “Build a Bank Account Class” stage, so let’s begin doing it. First video: Part 1: Create the Class

Here is the code:

And the result:

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ ruby bank_account.rb
#

And the challenges:

Challenge Task 1 of 3

Create a new, empty class called BankAccount.

Challenge Task 2 of 3

Create an initialize method for the BankAccount class that takes one argument, name, which sets @name as an instance variable on initialization.

Challenge Task 3 of 3

In the initialize method, create an empty array called @transactions, which is an instance variable.

Video 2: Part 2: Transactions, credits, and debits

The code:

and the results:

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ ruby bank_account.rb
#“Beginning Balance”, :amount=>0}, {:description=>”Paycheck”, :amount=>100}, {:description=>”Groceries”, :amount=>-40}]>

Challenges:

Challenge Task 1 of 2

Create a method called add_transaction on the BankAccount class. The method should take two arguments: description and amount.

Challenge Task 2 of 2

Now that the add_transaction method exists, make the add_transaction method append a hash to the @transactions array. The hash should have the keys description and amount, as symbols, and values that match the arguments to the method.

Video 3: Part 3: Keeping Our Balance

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ ruby bank_account.rb
Name: Nick, Balance: 60.00

Challenge Task 1 of 1

In the BankAccount class, implement a method called balance. The balance method should loop through transactions and calculate the current account balance.

Video 4: Part 4: Printing the register

The code:

The results:

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ ruby bank_account.rb
Name: Nick, Balance: 49.49
Register:
Nick’s Bank Account
________________________________________
Description Amount
Beginning Balance 0.00
Paycheck 100.00
Groceries -40.00
Gas -10.51
________________________________________
Balance: 49.49
________________________________________

and the last challenge:

Challenge Task 1 of 1

Implement a to_s method on the BankAccount class that displays the name and balance in the following format (without brackets):
Name: [name], Balance: [balance]
It is not necessary to use the sprintf method to implement the balance printing.

Now, on to Learn Ruby the Hard Way,

So, first, the error above is he left off the “?” in the first include. Fixed.

The result:

demosthenes131@rails-tutorial:~/workspace/LRTHW $ ruby ex35.rb
You are in a dark room.
There is a door to your right, left or forward.
Which one do you take?
>right
Here you see the great evil Cthulhu.
He, it, whatever stares at you and you go insane.
Do you flee for your life or eat your head?
>flee
You are in a dark room.
There is a door to your right, left or forward.
Which one do you take?
>left
There is a bear here.
The bear has a bunch of honey.
The fat bear is in front of another door.
How are you going to move the bear?
>take honey
The bear looks at you then slaps your face off.
Good job!
demosthenes131@rails-tutorial:~/workspace/LRTHW $ ruby ex35.rb
You are in a dark room.
There is a door to your right, left or forward.
Which one do you take?
>left
There is a bear here.
The bear has a bunch of honey.
The fat bear is in front of another door.
How are you going to move the bear?
>taunt bear
The bear has moved from the door. You can go through it now.
>open door
This room is full of gold. How much do you take?
>49
Man, learn to type a number.
Good job!

Hmm.

Study Drills

1. Draw a map of the game and how you flow through it.

2. Fix all of your mistakes, including spelling mistakes.

Done.

3. Write comments for the functions you do not understand.

I think I get the functions except for in the gold room.

4. Add more to the game. What can you do to both simplify and expand it?

I will come back to this.

5. The gold_room has a weird way of getting you to type a number. What are all the bugs in this way of doing it? Can you make it better than what I’ve written? Look at how =~ works for clues.

The issue here is that I did type a number above and it did not see it. I am running out of time and need to get back to getting ready for company. I need to think about this some more…

Day 29: Some Hard Way and Treehouse!

So, I plan to do Exercise 34 at Learn Ruby the Hard Way and then finish the stage I couldn’t finish last night at Treehouse. Let’s get started:

Exercise 34: Accessing Elements of Arrays

So, this is about accessing items in an array. Here is the array Mr. Shaw gives us:

and then a list to answer:

  1. The animal at 1.
  2. The third (3rd) animal.
  3. The first (1st) animal.
  4. The animal at 3.
  5. The fifth (5th) animal.
  6. The animal at 2.
  7. The sixth (6th) animal.
  8. The animal at 4.

So, I think I will check my answers by writing a script. First, however, let me pick which will be called:

  1. ruby
  2. peacock
  3. bear
  4. kangaroo
  5. whale
  6. peacock
  7. platypus
  8. whale

And then the code, which I wrote myself:

And the result:

demosthenes131@rails-tutorial:~/workspace/LRTHW $ ruby ex34.rb
bear
ruby
peacock
kangaroo
whale
platypus
So if bear is first, then we can figure out the rest!

And Mr. Shaw also want us to do this:

For each of these, write out a full sentence of the form: “The first (1st) animal is at 0 and is a bear.” Then say it backwards: “The animal at 0 is the 1st animal and is a bear.”

I will trust him.

  1. The animal at 1 is the ruby. It is the second animal in the list.
  2. The third animal in the list is peacock. It is at 2.
  3. The first animal is the bear. It is at 0.
  4. The animal at 3 is the kangaroo. It is the fourth animal.
  5. The fifth animal is the whale. It is 4.
  6. The animal at 2 is the peacock. It is third.
  7. The sixth animal is the platypus. It is at 5.
  8. The animal at 4 is the whale. It is at fifth.

And the study drills:

1. With what you know of the difference between these types of numbers, can you explain why the year 2010 in “January 1, 2010,” really is 2010 and not 2009? (Hint: you can’t pick years at random.)

Well, it is a string the way it is written. I also wonder if it has something to do with Ruby sees years. Not sure, however.

2. Write some more arrays and work out similar indexes until you can translate them.

I mean, I think I have it but here is one more in code:

demosthenes131@rails-tutorial:~/workspace/LRTHW $ ruby studydrill34.rb
Mad Max Fury Road
Ghostbusters
Casablanca
Avengers
Star Wars
Big Trouble in Little China
While right now the first movie in the list is Mad Max Fury Road, Big Trouble in Little China is definitely not last in my book.

3. Use Ruby to check your answers.

DONE!

Now on to Treehouse.

First video: Methods

and the results:

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ ruby name.rb
Mr. Nick Teddy Queen
Ms. Meredith Page Queen

Challenge Task 1 of 1

In the Name class, create a method called full_name that returns a string of the first_name and last_name with a space in between.

Next video: Instance Variables and Local Variables

The code:

And the results in IRB:

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ irb -r “./name.rb”
Mr. Nick Teddy Queen
Ms. Meredith Page Queen
>> name = Name.new(“Mr.”, “Nick”, “Teddy”, “Queen”)
=> #
>> name.full_name
=> “Nick Teddy Queen”
>> name.first_and_middle_name
=> “Nick Teddy”

And last video: The to_s method

First code:

and results:

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ ruby name.rb
Mr. Nick Teddy Queen
#
Ms. Meredith Page Queen
#

And the second code, after overriding the to_s method:

And a look at the .inspect method:

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ ruby name.rb
Mr. Nick Teddy Queen
Mr. Nick Teddy Queen
#
demosthenes131@rails-tutorial:~/workspace/TreeHouse $

Challenge Task 1 of 1

Create a to_s method for Name that returns the first_name and last_name separated by a space.

All done for tonight!

Day 28: Part, Two: Some Treehouse

OK, its late and it was a long day but I am committed to continuing. Let’s get to it:

Video 1: Variables

Here is the code. Note that this is the same name.rb file from the last Ruby lesson at Treehouse. We also changed the way the puts statements at the end were written:

And the result:

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ ruby name.rb
Mr. Nick Teddy Queen

Challenge Task 1 of 4

In the initialize method of the Name class, set an instance variable called @title to the title argument. Note: you will have to write the initialize method.

Challenge Task 2 of 4

Below the Name class, instantiate a new Name instance set to the variable name with any title you choose.

Challenge Task 3 of 4

Inside the Name class, create a method called title that returns the @title variable.

Challenge Task 4 of 4

Call the title method on the name instance.

Video 2: Attribute Readers

The code:

Wow. That is a really neat code!

The result is the same:

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ ruby name.rb
Mr. Nick Teddy Queen

Challenge Task 1 of 1

In the Name class, create an attr_reader for the title instance variable.

Video 3: Attribute Writers and Accessors

First some work in IRB:

And having not been able to give myself a doctorate, we need to go into the file and fix this travesty!

OR, we can use attr_writer, and past that, attr_accessor which does reader and writer:

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ ruby name.rb
Mr. Nick Teddy Queen
Title: Mr.
Title: Dr.

Challenge Task 1 of 2

In the Name class, create an attr_writer for the first_name instance variable.

Challenge Task 2 of 2

In the Name class, create an attr_accessor for the last_name instance variable.

And that is it for tonight. I am halfway through this stage. Will finish tomorrow!

Day 28, Part One: Exercise 33 of Learn Ruby the Hard Way

I have some time before work so want to keep studying!

Time for Exercise 33: While Loops

And the result:

demosthenes131@rails-tutorial:~/workspace/LRTHW $ ruby ex33.rb
At the top is 0
Numbers now:
0
At the bottom i is 1
At the top is 1
Numbers now:
0
1
At the bottom i is 2
At the top is 2
Numbers now:
0
1
2
At the bottom i is 3
At the top is 3
Numbers now:
0
1
2
3
At the bottom i is 4
At the top is 4
Numbers now:
0
1
2
3
4
At the bottom i is 5
At the top is 5
Numbers now:
0
1
2
3
4
5
At the bottom i is 6
The numbers:
0
1
2
3
4
5

And on to the study drills:

1. Convert this while-loop to a function that you can call, and replace 6 in the test (i < 6) with a variable.

This was hard. I ended up writing it through twice and having to go back to read the function lessons again. My first try I got this error:

Basically, it tells me I was not passing in the correct number of arguments. I was trying to define i in the function. I took that out and then called the arguments correctly, which looks like this:

And to my surprise it works! This is so important to me. I have had doubts that I was just mimicing what I read and not really learning. I had that initial feeling of “oh crap,” seeing this study drill. I then slowed down and thought through it. I read back over past lessons. I knew I had to use def and then just write inside it the while loop. From there I tweaked until it worked. And it did!

The results:

demosthenes131@rails-tutorial:~/workspace/LRTHW $ ruby studydrill33.rb
At the top is 0
Numbers now:
0
At the bottom i is 1
At the top is 1
Numbers now:
0
1
At the bottom i is 2
At the top is 2
Numbers now:
0
1
2
At the bottom i is 3
At the top is 3
Numbers now:
0
1
2
3
At the bottom i is 4
At the top is 4
Numbers now:
0
1
2
3
4
At the bottom i is 5
At the top is 5
Numbers now:
0
1
2
3
4
5
At the bottom i is 6

2. Use this function to rewrite the script to try different numbers.

The great thing with functions is that you can quickly change the arguments you pass to them. I went ahead and added a second argument to the function, removing widgets from inside it and passing it through in an argument. I then tried it and here is the result:

The code:

Here is the result:

demosthenes131@rails-tutorial:~/workspace/LRTHW $ ruby studydrill33.rb
At the top is 3
Numbers now:
3
At the bottom i is 4
At the top is 4
Numbers now:
3
4
At the bottom i is 5
At the top is 5
Numbers now:
3
4
5
At the bottom i is 6
At the top is 6
Numbers now:
3
4
5
6
At the bottom i is 7
At the top is 7
Numbers now:
3
4
5
6
7
At the bottom i is 8
At the top is 8
Numbers now:
3
4
5
6
7
8
At the bottom i is 9
At the top is 9
Numbers now:
3
4
5
6
7
8
9
At the bottom i is 10
At the top is 10
Numbers now:
3
4
5
6
7
8
9
10
At the bottom i is 11
At the top is 11
Numbers now:
3
4
5
6
7
8
9
10
11
At the bottom i is 12
At the top is 12
Numbers now:
3
4
5
6
7
8
9
10
11
12
At the bottom i is 13
At the top is 13
Numbers now:
3
4
5
6
7
8
9
10
11
12
13
At the bottom i is 14
At the top is 14
Numbers now:
3
4
5
6
7
8
9
10
11
12
13
14
At the bottom i is 15
At the top is 15
Numbers now:
3
4
5
6
7
8
9
10
11
12
13
14
15
At the bottom i is 16
At the top is 16
Numbers now:
3
4
5
6
7
8
9
10
11
12
13
14
15
16
At the bottom i is 17
At the top is 17
Numbers now:
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
At the bottom i is 18
At the top is 18
Numbers now:
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
At the bottom i is 19
At the top is 19
Numbers now:
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
At the bottom i is 20

I am amazed that I am finally getting this more and more. Yay!

3. Add another variable to the function arguments that you can pass in that lets you change the + 1 on line 8 so you can change how much it increments by. and 4. Rewrite the script again to use this function to see what effect that has.

The code:

The result:

demosthenes131@rails-tutorial:~/workspace/LRTHW $ ruby studydrill33.rb
At the top is 3
Numbers now:
3
At the bottom i is 7
At the top is 7
Numbers now:
3
7
At the bottom i is 11
At the top is 11
Numbers now:
3
7
11
At the bottom i is 15
At the top is 15
Numbers now:
3
7
11
15
At the bottom i is 19
At the top is 19
Numbers now:
3
7
11
15
19
At the bottom i is 23

And that is all the time I have. I will continue at the end of this exercise when I return later! So excited!

Return of Day 27: Back in the Treehouse

So, I have a little more time and decided to work on a little Treehouse.

Video 1: Ruby Classes

And this is just an overview of the idea of Ruby classes, which I covered in Michael Hartl’s tutorial.

Video 2: Instantiation

OK, this goes a little deeper. We discuss creating new objects and the difference between classes and instances. The act of creating an instance of a class is called instantiation. Once created, that instance is called an object. Take a look at the irb session below:

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ irb
>> string = String.new
=> “”
>> string.class
=> String
>> nick = String.new(“Nick”)
=> “Nick”
>> Array.new
=> []
>> Hash.new
=> {}
>> exit

And then some code:

And the result:

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ ruby myclass.rb
This is the initialize method.

And the challenge:

Challenge Task 1 of 2

Instantiate a new instance of the String class and assign the newly instantiated instance to the variable string.

Challenge Task 2 of 2

Instantiate a new instance of the Array class and assign the newly instantiated instance to the variable array.

Video 3: Ruby Objects

So, object oriented programming. I have heard of it a lot but this was the first direct discussion of it.

Challenge Task 1 of 1

Using the respond_to? method, ask the string variable if it responds to the upcase method. Remember, the respond_to? method can take a string or a symbol as an argument.

Video 4: Creating a Class

The one thing I can say I like about TreeHouse is that it gives the lessons in nice, bite-sized chunks but that they are also easy to follow, even when really difficult stuff. This isn’t necessarily difficult, and it may be because its my second time doing this, but I am beginning to understand the idea of creating a class.

The code:

So, we create a class named “Name” and then defined three methods underneath it, and then called them.

This is the location in Ruby of what we created:

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ ruby name.rb
#

and here we run it and call each method:

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ ruby name.rb
Mr.
Nick
Teddy
Queen

Challenge Task 1 of 3

Instantiate an instance of the Name class and assign it to the variable name. This must come after the definition of the Name class.

Challenge Task 2 of 3

Call the puts method with the name variable’s first_name method as an argument.

Challenge Task 3 of 3

On the next line, call the puts method with the name variable’s last_name method as an argument.

Another badge!

Day 27: A Short Evening of Study

A long day of work and company coming on Thursday night which I need to do some housework to prepare for means I will have a few short nights of study. Today I am focusing on Learn Ruby the Hard Way, Exercise 32: Loops and Arrays.

Here is the code from the lesson:

And the result:

demosthenes131@rails-tutorial:~/workspace/LRTHW $ ruby ex32.rb
This is count 1
This is count 2
This is count 3
This is count 4
This is count 5
A fruit of type: apples
A fruit of type: oranges
A fruit of type: pears
A fruit of type: apricots
I got 1
I got pennies
I got 2
I got dimes
I got 3
I got quarters
adding 0 to the list.
adding 1 to the list.
adding 2 to the list.
adding 3 to the list.
adding 4 to the list.
adding 5 to the list.
Element was: 0
Element was: 1
Element was: 2
Element was: 3
Element was: 4
Element was: 5

And the study drills:

1. Take a look at how you used (0..5) in the last for-loop. Look up Ruby’s “range operator” (.. and …) online to see what it does.

I worked with ranges at TreeHouse and I feel pretty familiar with with what it does. Read more about ranges here.

2. Change the first for number in the_count to be a more typical .each style loop like the others.

OK. I did this:

and it worked!!!!

demosthenes131@rails-tutorial:~/workspace/LRTHW $ ruby ex32.rb
This is count 1
This is count 2
This is count 3
This is count 4
This is count 5
A fruit of type: apples
A fruit of type: oranges
A fruit of type: pears
A fruit of type: apricots
I got 1
I got pennies
I got 2
I got dimes
I got 3
I got quarters
adding 0 to the list.
adding 1 to the list.
adding 2 to the list.
adding 3 to the list.
adding 4 to the list.
adding 5 to the list.
Element was: 0
Element was: 1
Element was: 2
Element was: 3
Element was: 4
Element was: 5

3. Find the Ruby documentation on arrays and read about them. What other operations can you do besides the push function? Try <<, which is the same as push but is an operator. fruits << x is the same as fruits.push(x).

And it works. It is near the end. I actually thought I screwed up, broke it to make it mess up and redid it. I was shocked I got it right. I remember it from TreeHouse but it was a vague memory.

demosthenes131@rails-tutorial:~/workspace/LRTHW $ ruby ex32.rb
This is count 1
This is count 2
This is count 3
This is count 4
This is count 5
A fruit of type: apples
A fruit of type: oranges
A fruit of type: pears
A fruit of type: apricots
I got 1
I got pennies
I got 2
I got dimes
I got 3
I got quarters
adding 0 to the list.
adding 1 to the list.
adding 2 to the list.
adding 3 to the list.
adding 4 to the list.
adding 5 to the list.
Element was: 0
Element was: 1
Element was: 2
Element was: 3
Element was: 4
Element was: 5

And that is it tonight!