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 () 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 () below!
Agree with a comment or answer? Like () to up-vote the contribution!
Hola! Lo siento para mi mal español, pero sí. a_lambda es el parámetro y lamda es el argumento. El parámetro es un marcador de posición para el argumento.
So you nest a block in a block by putting it as the argument? I think that what is exercise is telling us something without actually saying it directly. And it is that you can have a block, more specifically a Proc or a Lambda, as an argument in a method. Why would one need to do that, I do not know yet.
This may seem confusing since we literally just learned what a ‘lambda’ is and now we are ‘interpolating’ blocks in arguments in methods, in which a method can be thought of as a block, but that is what I think is going on here. The lambda is the argument, to the method.
I’m glad you’ve figured it out, @chadw1ck! All I have to contribute is my annoyance with the overuse of the word “lambda” throughout the example - it makes it very hard to follow what is happening. For anyone else, I believe that lambda_demo is the lambda, and a_lambda is a parameter. If I substitute other words to make sense of it, it looks like this:
def demo(my_parameter)
puts "I'm the first!"
my_parameter.call
end
demo(lambda { puts "I'm the second!" })
I don’t understand what’s happening in this exercise or the explanations given above. I’d be very grateful if someone could put it in plain terms for me please.
I understand that we’ve defined a method called lambda_demo, which takes one parameter - (a_lambda), but why do we suddenly call (a_lambda) on line 3?
On line 6 we call lambda_demo with lambda, but how does Ruby know what lambda is? Don’t we need to define lambda somewhere?
Are we defining lambda and a calling it with the same line of code on line 6?
lambda_demo() is the method being called in line 6. The argument to that call is where the lambda (a block) is defined. It is then called within the demo method.