Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
- Contact Class: Part 1 6:05
- Create a Contact Class 1 objective
- Contact Class: Part 2 4:04
- Write a Method 1 objective
- Phone Number Class 6:15
- Write a to_s Method 1 objective
- Address Class: Part 1 5:00
- Address Class: Part 2 3:44
- Initializing and Calling Methods 2 objectives
- Address Book Class 4:25
- Instance variable instantiation 2 objectives

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
The first part of our address book application that we'll address is creating a class to store our contacts. Unsurprisingly, we're calling this the Contact
class!
Code Samples
class Contact
attr_writer :first_name, :middle_name, :last_name
def first_name
@first_name
end
def middle_name
@middle_name
end
def last_name
@last_name
end
def full_name
full_name = first_name
if !@middle_name.nil?
full_name += " "
full_name += middle_name
end
full_name += ' '
full_name += last_name
full_name
end
end
jason = Contact.new
jason.first_name = "Jason"
jason.last_name = "Seifer"
puts jason.full_name
nick = Contact.new
nick.first_name = "Nick"
nick.middle_name = "A"
nick.last_name = "Pettit"
puts nick.full_name
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
K .
2,357 Points1 Answer
-
Shreemangal Sethi
Full Stack JavaScript Techdegree Student 15,552 PointsInstance Variable
1 Answer
-
Alexander Mooney
7,321 Points2 Answers
-
Sean Flanagan
33,236 Points2 Answers
-
Patrick Shushereba
10,911 Points1 Answer
-
PLUS
kabir k
Courses Plus Student 18,036 Points2 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up