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