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
Post a Comment