FAQ: Object-Oriented Programming II - Mixin for the Win

This community-built FAQ covers the “Mixin for the Win” exercise from the lesson “Object-Oriented Programming II”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Ruby

FAQs on the exercise Mixin for the Win

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 (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 (reply) below!

Agree with a comment or answer? Like (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!

I received a warning “(ruby):1: warning: already initialized constant Context::Languages::FAVE
(ruby):1: warning: previous definition of FAVE was here”

Is this because this space has been used by others?

That would explain the “Ghost codes” we have been seeing.

What is the purpose of putting “def initialize; end” here if it doesn’t do anything?

class Master
include Languages
def initialize; end
def victory
puts FAVE
end
end

Remove that line and this error occurs:

(ruby):1: warning: already initialized constant Context::Languages::FAVE
(ruby):1: warning: previous definition of FAVE was here

Replace that line and Run, then refresh, and Run. No error reported. Now Run again and we get the same error.

There is some mystery here which will take further exploration to understand what the error message is telling us.

Still not sure why the error occurs on a second run, other than that the instance is already (still) present in memory and cannot be overwritten. Hopefully a Ruby aficionado discovers this topic and sheds some serious light on the question.

Just tried removing the initialize method, Run and Refresh, and Run again. The error does not get raised. Obviously not much help. Going to have to keep digging for clarity.

warning: already initialized constant

This solves the problem, but does not explain it…

module Languages
  FAVE ||= "Ruby"  # conditional assignment
end