Can you put multiple assignment in rescue modifier?
-
07-07-2021 - |
题
Suppose I have this :
item_one = Object.find(1) rescue item_one, value = [Object.first, true]
This actually does not work. It returns this :
syntax error, unexpected '=', expecting $end
Does anyone know how to syntactically put multiple assignment in rescue modifier?
Side note:
Boris recommend setting up rescue statements this way :
begin
i1 = Object.find 1
rescue NoMethodError
i1, v = Object.first, true
end
解决方案
Use parenthesis. So you are rescuing from the assignment:
(item_one = Object.find(1)) rescue item_one, value = [Object.first, true]
不隶属于 StackOverflow