9.A vous de jouer ! (Blocs, procs et lambdas)


I type:
def bonjour

phrase = Proc.new { puts "Bonjour !" }

and Ruby said me:
Oups, merci de réessayer. Votre syntaxe est incorrecte. no block given (yield)

Please, someone could help me?


The goal is to give the proc to bonjour, not to select. At least I think, I don't know which exercise it is, it should be in the instructions.


Thks for your reply

Ok, instructions said
1- to create a def 'bonjour' without (n) and with a yield.
2- to create a proc 'phrase' which puts 'bonjour!' and then to link the proc to the def 'bonjour'
No more instruction. I don't understand why Ruby said 'no block given (yield)'

It's the exercise 9 of the block proc and lambda of Ruby.
Trick said:
1-def name_methode
2-name_proc = Proc.new do
puts "Text"



Because the exercise is expecting you to give the proc to the bonjour method, not to the select method.

That's what they mean by: "link the proc to the def 'bonjour'"


Ok, sorry, so I don't understand what's the difference between 'give a proc to a method' and 'select a method' in terms of code. Could you show me examples please?


You don't select a method. select is a method itself.

By calling bonjour.select(&phrase), you're calling the method bonjour and chaining it to the method select which will receive the proc phrase. But that's not what's expected. They expect you to give the proc directly to the bonjour method.

How do you think you will do that (just take inspiration from how select receives the proc)?


lol, you make me crazy, it's 1:20am in France, I'm tired, and it's a little bit difficult for me to translate in English ! But I really appreciate that you want make me found by myself the solution… I try


That's what you get for coding so late ^^. I'll give you the answer if you don't succeed.


I'm going to sleep now, I'll give you another hint:

When you type:

puts "Bonjour!"

You're giving the object "Bonjour!" to the method puts.

Another way to type this is:



I read and read last 3 lessons, and I don't understand..maybe a problem of translation between french and english ?
My method is 'bonjour'
My proc is 'phrase'
My goal is to give the proc 'phrase' to the method 'bonjour'
vbv ggbvf (<-- sorry it's my cat)
so I give a proc like that (&phrase)
and we have bonjour(&phrase)
I try … drums rolls...




Many thanks for your patience


Great that it worked. Good luck for the rest of the course.