FAQ: Ordering Your Library - Default Parameters

This community-built FAQ covers the “Default Parameters” exercise from the lesson “Ordering Your Library”.

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

Learn Ruby

FAQs on the exercise Default Parameters

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!

4 posts were split to a new topic: How do you overload methods in Ruby?

What this does is tell Ruby that alphabetize has a second parameter, rev (for “reverse”) that will default to false if the user doesn’t type in two arguments.

What does it mean that it will default to false?

1 Like

“You might have noticed that our first call to alphabetize in exercise 1 was just alphabetize(books). Ruby didn’t see a rev , so it gave it the default value of false.”

Ruby didn’t see a ‘rev’, so it gave what the default value of ‘false’? The second parameter? But there is no second parameter in ‘alphabetize(books).’

alphabetize is a custom method that leverages the Array#sort method, which method has an optional parameter, rev that defaults to false if not specified.