Day 26, Part 2: Some More Treehouse and a Recap

So, first, a recap of my current efforts:

  1. I started on May 27, 2015 with Codecademy HTML and CSS course and then moved on to Michael Hartl’s Ruby on Rails tutorial. I decided after Chapter 4 that i would focus on building up my Ruby proficiency and then return to it.
  2. I went from there to Zed Shaw’s Learn Ruby the Hard Way. I am currently on Exercise 32: Loops and Arrays.
  3. I have also signed up for TreeHouse and I am in my free month at present. I just added a widget with all the badges in the sidebar.
  4. My plan is to return to Hartl’s Ruby on Rails tutorial after completing TreeHouse’s Ruby portion and Learn Ruby the Hard Way.

So, tonight I plan to finish another portion of the TreeHouse Ruby track.

First video tonight is: Part 1: Asking Questions.

The code:

and the results:

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ ruby contact_list.rb
What is your name? Nick
Nick

Challenge Task 1 of 1

Fill out the parse_answer method to return the answer passed in. If the kind is number, convert it to an integer using the to_i method before returning it.

Next video: Part 2: Adding Contacts

The code:

and the results:

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ ruby contact_list.rb
What is the person’s name? Nick
Do you want to add a phone number? (y/n) y
Enter a phone number: 555
Do you want to add a phone number? (y/n) y
Enter a phone number: 454
Do you want to add a phone number? (y/n) 343
Do you want to add a phone number? (y/n) y
Enter a phone number: 654
Do you want to add a phone number? (y/n) n
Add another? (y/n) y
What is the person’s name? Jason
Do you want to add a phone number? (y/n) y
Enter a phone number: 765
Do you want to add a phone number? (y/n) n
Add another? (y/n) n

Challenge Task 1 of 3

Assign the value of the key name to the return value of the method get_name() in the contact hash. Assume that get_name() returns a string.

I had to look up an explanation for this one and found others found it confusing. Here is the answer:

This has to do with assigning the get_name() as the return value in the hash.

Key-Values Pairs : Hash = { KEY, VALUES }

Weird, and I think it was worded weirdly.

Challenge Task 2 of 3

Assign the value of the key phone_number to the return value of the method get_phone_number() in the contact hash. Assume that get_phone_number() returns a string.

Hmm. Again, the same.

Challenge Task 3 of 3

Append the contact hash to the contact_list array.

Last video: Part 3: Printing The Contact List

The code:

And results:

demosthenes131@rails-tutorial:~/workspace/TreeHouse $ ruby contact_list.rb
What is the person’s name? Nick
Do you want to add a phone number? (y/n) y
Enter a phone number: 787
Do you want to add a phone number? (y/n) n
Add another? (y/n) y
What is the person’s name? Jason
Do you want to add a phone number? (y/n) y
Enter a phone number: 765
Do you want to add a phone number? (y/n) y
Enter a phone number: 987
Do you want to add a phone number? (y/n) n
Add another? (y/n) y
What is the person’s name? Ryan
Do you want to add a phone number? (y/n) y
Enter a phone number: 897
Do you want to add a phone number? (y/n) n
Add another? (y/n) n
___
Name: Nick
Phone: 787
___
Name: Jason
Phone: 765
Phone: 987
___
Name: Ryan
Phone: 897

Challenge Task 1 of 1

Using the each method, iterate over the contact_list array. Assign each array item to the local variable contact in the block and print out the value of the name and phone_number keys.

And I am done for tonight!