FAQ: Blocks, Procs, and Lambdas - Proc Syntax

This community-built FAQ covers the “Proc Syntax” exercise from the lesson “Blocks, Procs, and Lambdas”.

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

Learn Ruby

FAQs on the exercise Proc Syntax

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!

When and why using proc is preferable than using method?
I’m sorry it’s still unclear to me.

1 Like

it is for not to write the same block over and over, you can “save it” as a proc, so you dont have to write the same block every time you need it.

this is just for the Blocks, not for an entire method, you can have entire methods that do things and inside that methods you can have procs to simplify you life :slight_smile:

Can .each method accept a block?
Why the following code works, but if we substitute .collect with .each, it doesn’t?

floats = [1.2, 3.45, 0.91, 7.727, 11.42, 482.911]
round_down = Proc.new { |x| x.floor }
puts floats.collect(&round_down)
1 Like

I believe that collect alters what it was called on while each doesn’t. It might be more complicated than that, though.

The other question I have is - what is the point of having both collect and map if they’re truly identical?


What is the difference between .collect and .select methods?

I’m curious why I would want to define a Proc rather than just defining a helper function and calling that function where needed?

1 Like