Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Ruby Objects and Classes!
You have completed Ruby Objects and Classes!
Preview
In this video, we create a simple class. The class will be modeled after the concept of a name and return the different attributes a name might have.
Code Samples
class Name
def title
"Mr."
end
def first_name
"Jason"
end
def middle_name
""
end
def last_name
"Seifer"
end
end
name = Name.new
puts name.title
puts name.first_name
puts name.middle_name
puts name.last_name
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
We'll start small and create a class for
representing a name.
0:00
Before we jump straight in to coding, let's
think about how a name can be structured.
0:02
We're not going to get into everything
that can be possible with a name.
0:07
But for the purposes of the class we're
going to write, a name could have
0:11
the following items, title, first name,
middle name, and last name.
0:15
We create a class using the class keyword,
and
0:22
then the name of the class that we wanna
create.
0:25
Let's see how that works now using Work
Spaces.
0:28
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