FAQ: Methods, Blocks, & Sorting - Call It!

This community-built FAQ covers the “Call It!” exercise from the lesson “Methods, Blocks, & Sorting”.

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

Learn Ruby

FAQs on the exercise Call It!

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!

Can i get some examples of “call it” please?

ex.

def array_of_10
puts (1…10).to_a
end

Call to method…

array_of_10()

Output

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

I can never remember which range operator is inclusive and which is exclusive. Above the assumption is ... is inclusive.


Edit

Gets me every time. I had a hunch that ... is exclusive, and .. is inclusive. The output above should read,

[1, 2, 3, 4, 5, 6, 7, 8, 9]

To include the 10, use

puts (1..10).to_a
1 Like

THANK YOU SOOO MUCH!!! You are a code savior!! I have tried both ways with “...” and “..”!

2 Likes

You’re welcome!

Another gotcha that made me go back and check…

def array_of_10

The above signature line has no parameter. That means we can call it without an argument list…

array_of_10

This Ruby stuff may be fine for children, but us grown-ups are always on the hook where those binary decisions have to be made. (LOL)

What’s really neat about this is we store objects in methods, rather than giving them variables.

def array_of_10
    (1..10).to_a
end

puts array_of_10
[1, 2, 3, 4, 5, 6, 7, 8, 9]

And getting into more fun stuff…

puts array_of_10.map {|x| x * 2}

Output

[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]

The array_of_10 method is truly a reusable object in every regard. And nary an assignment.

1 Like