ruby ternary operator syntax - spacing between operator -


is following line proper ruby syntax?

session[:id]?'foo':'bar' 

(notice there no spacing between operators)

this line works rubies tried (>1.8.7) understand there can misunderstanding ? can part of method identifier.

shouldn't syntax error not put spaces arround ternary operator?

i believe correct forms ternary operator when selector indexed hash, because char combination ]? invalid same operator:

session[:id]?'foo':'bar' session[:id] ? 'foo' : 'bar' session[:id]? 'foo' : 'bar' 

but if omit space after just method , the question mark, raise syntax error:

session?'foo':'bar'           ^ syntaxerror: unexpected ':', expecting $end session? 'foo':'bar'            ^ syntaxerror: unexpected ':', expecting $end 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -