+ 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
2 Antworten
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."}
0
Because the interpreter thinks that you are providing block to the say method, not something. Parentheses it is not always a bad idea :)