Do I need to parenthesise yield in Ruby?
-
05-07-2019 - |
Question
In Ruby I can use
result << (yield element)
and everything works, but if I do
result.push(yield element)
I get a warning about needing parentheses for future compatibility. I can change the above to
result.push(yield(element))
and the interpreter is happy again, but I don't understand why I need parentheses in one call to yield and not the other?
Solution
You can ignore that warning. You won't get it anymore in 1.8.7 and later. The planned parser changes that were the reason for this warning, have been dismissed.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow