Blocks Quiz Unpassable

2 Issues:

  • Quiz questions are doubled (1…8 == 9…16)

  • Question 7 (and 15) does not pass when correct answers (per explanation) are selected.

I think they might have just mixed the order in which the choices were given? By their explanation, the correct answers would be 1. where the & is applied to the last parameter (the second choice -> def procs_everywhere(proc1, proc2, &proc3) and 2. where there is no & because all the Procs could be pre-wrapped (the first choice -> def procs_everywhere(proc1, proc2, proc3).

The quiz questions were doubled for me too, I’m not sure why but you just have to put in the same answer twice I guess!

I have the same issue.
It seems that questions 7 and 15 have no correct answer (programmed). I think the correct answer should be: def procs_everywhere(proc1, proc2, &proc3). It says the correct answer is option 1: def procs_everywhere(&proc1, proc2, proc3)

Also all questions are duplicated.

Hi gabeross,

There are correct answers to questions 7/15 that will allow you to pass the quiz. There are two correct answer choices.
One of them as you’ve mentioned is def procs_everywhere(proc1, proc2, &proc3). The rule here is only the last argument can have the & sign. The ‘&’ sign is used to turn a block into a proc (proc3 is actually a block in this case), but Ruby can only wrap one block at a time. So by Ruby rules, named block argument, aka proc3, is always the last argument in an list of argument for a method.
The second correct answer is def procs_everywhere(proc1, proc2, proc3). In this scenario, all the arguments are procs so you do not have to worry about any conversion of blocks to procs.
Hope this helps!

Yes, they are duplicated…

Michael

Thanks Michael.

That did work.
I’m confused about why both are correct answers.
If all three are procs, then why would the & on proc3 turn it into a proc? Doesn’t it to the opposist in that case?

Are they procs simply by virtue of being called “proc1” etc…
I thought some code was needed in a helper method in order to turn proc1 and proc2 into procs and only on the last could & be used.

Hi gabeross,

Ah, good catch. You are right. The & sign, in this case, turns proc3 into a block not the other way around. My bad on that.
For this example, we are assuming the procs given to us are procs already created somewhere else in the file. These procs can be called individually and will all work. This question is mainly testing the fact you can only have one block as an argument and it has to be the last argument.

Aloha Mr. Ruan,

May I ask why would anyone use a proc over a method? What benefits do procs bring except for being able to be defined with a single line of code? Do you by chance have an example of a great use case for a proc?

Thank you so much. Only started learning Ruby 3 days ago. It’s interesting compared to JavaScript.

Mahalo,
Steven

Hi Steven,

A proc is way more flexible than a method. You can store proc as variables and pass around as an argument. A method can only be called. You can convert a class method into a proc-like object using the method, method, but this is too advanced for you to worry about. I do not have a great example of a proc, but you will get more practice with them as you work through the Alpha Course.

-Michael