Question

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
Was it helpful?

Solution

Use parenthesis. So you are rescuing from the assignment:

(item_one = Object.find(1)) rescue item_one, value = [Object.first, true]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top