This community-built FAQ covers the “Classing It Up” exercise from the lesson “Object-Oriented Programming I”.
Paths and Courses
This exercise can be found in the following Codecademy content:
Learn Ruby
FAQs on the exercise Classing It Up
There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (
) below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply (
) below!
Agree with a comment or answer? Like (
) to up-vote the contribution!
Need broader help or resources? Head here.
Looking for motivation to keep learning? Join our wider discussions.
Learn more about how to use this guide.
Found a bug? Report it!
Have a question about your account or billing? Reach out to our customer support team!
None of the above? Find out where to ask other questions here!
This was so frustrating!!
why the double end??
class Person
def initialize
end
end
Hello,
Well, let’s break it down.
First, you instantiate a class named Person.
class Person
end
end
tells the program where and when the class ends.
Then, you create a method called initialize
within that Person
class.
def initialize
end
end
tells the program where and when your method ends.
Let’s imagine that you want to say hello to someone.
class Person
def initialize(name = "David")
@name = name
end
def say_hello
puts "Hello #{@name}!"
end
end
// Hello David!
You see, that’s a way to structure your code into blocks. def
will begin a method, and end
will stop it. class
will start a class, and end
will tell the program where that class ends.
Without that, the program would have no way of knowing where to start, when to stop, and when to move on to something else.
2 Likes
Hello,
I’m stuck on the method name “initialize”.
When we create our own methods using def, we can give it any name/word we want, right?
Is “initialize” a Ruby built-in method like .map and .length?
Is the name “initialize” a reserved word? Would any name/word work instead of initialize?
Or if “initialize” is a Ruby’s method, so why do we use def, as if we were creating our own method if the method already exists? sorry if this is a dumb question
I think I might me mixing all the concepts here x(
Edit: I think this kind of explains the method… Leaving this here in case someone has the same question in the future. (I’m still a bit confused heh)
Initialize
thank you very very myuch! ^^
1 Like