Why the output is “hi” not “bye”? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

Why the output is “hi” not “bye”?

def say(*args) args[0].call end def something if block_given? return yield end lambda{p "hi."} end say something do lambda{p "bye."} end

10th Nov 2019, 2:19 AM
BIGBEN
BIGBEN - avatar
2 Respuestas
0
if you want to output "bye" then "hi": def say(*args) args[0].call end def something if block_given? yield end lambda{p "hi."} end say something {p "bye."}
10th Nov 2019, 8:15 AM
Veliside
Veliside - avatar
0
Because the interpreter thinks that you are providing block to the say method, not something. Parentheses it is not always a bad idea :)
7th Dec 2019, 1:45 AM
Alex Tatarnikov