Is there a way to make this Ruby ternary operation evaluate properly?
ruby, ternary-operator
Solution
How about:
@going, @not_going = invite.accepted ? ['selected', ''] : ['', 'selected']
`w, x = y, z` is the same as `w, x = [y, z]`, so this works just fine and there is no repetition.
Problem
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' ) %> ```