The following line of code
<% invite.accepted ? { @going, @not_going = 'selected', '' } : { @going, @not_going = '', 'selected' } %>
is my attempt at condensing several operations (evaluating an expression and setting the values of two variables accordingly) into a single line.
It kicks up an error, claiming there’s an unexpected comma.
Is there a way to make this work, or am I just overloading the poor ternary operator?
(This was just a personal experiment, by the way. I don’t mind using a simple — albeit cumbersome — if/else statement)
EDIT: The following line of code works! I’ll check off the proper answer as soon as I can!
<% invite.accepted ? ( @going, @not_going = 'selected', '' ) : ( @going, @not_going = '', 'selected' ) %>
How about:
w, x = y, zis the same asw, x = [y, z], so this works just fine and there is no repetition.