Ruby Question one line if statement - Stack Overflow
stackoverflow.com
"In Ruby, the condition and the then part of an if expression must be separated by either an expression separator (i.e. ; or a newline) or the then keyword.
So, all of these would work:
if @item.rigged then 'Yes' else 'No' end
if @item.rigged; 'Yes' else 'No' end
if @item.rigged
'Yes' else 'No' end"
"
"n Ruby, however, if is an expression. In fact, everything is an expression in Ruby, so it already can return a value. There is no need for the conditional operator to even exist, let alone use it."
#control_statements #if_statements #ruby #grammar #pub
Collect and share the web
Get started for free