You just learned how to write a class definition with an initialize method. But it takes time for some concepts to sink in. Tats why you're going to partner up and explain your understanding in your own words.
- Partner up.
- Examine the code below with your partner.
- With your partner, answer the questions that follow.
class Student
def initialize(f_name, l_name, occupation)
@first_name = f_name
@last_name = l_name
@prior_occupation = occupation
end
def first_name=(x)
@first_name = x
end
def first_name
return @first_name
end
end
student_one = Student.new("Chadd", "Clairmont", "Scuba Diving Instructor")
student_two = Student.new("Kristen", "Macfarlane", "Academic")In the code above:
- What is
class? - What is
Student? - What type of method is
first_name=? - What type of method is
first_name? - What type of variable is
@first_name? - What does the
initializemethod do? - When does the
initializemethod execute? - What's the difference between a class and an instance?
- What type of object does the variable
student_onehold? - What type of object does the variable
student_twohold? - What will the return value of
student_one.first_namebe? - What will the return value of
student_two.first_namebe?