Is there a way to make this Ruby ternary operation evaluate properly? -


the following line of code

<% invite.accepted ? { @going, @not_going = 'selected', '' } : { @going, @not_going = '', 'selected' } %> 

is attempt @ condensing several operations (evaluating expression , setting values of 2 variables accordingly) single line.

it kicks error, claiming there's unexpected comma.

is there way make work, or overloading poor ternary operator?

(this personal experiment, way. don't mind using simple -- albeit cumbersome -- if/else statement)

edit: following line of code works! i'll check off proper answer can!

<% invite.accepted ? ( @going, @not_going = 'selected', '' ) : ( @going, @not_going = '', 'selected' ) %> 

how about:

@going, @not_going = invite.accepted ? ['selected', ''] : ['', 'selected'] 

w, x = y, z same w, x = [y, z], works fine , there no repetition.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -