<%if @item.rigged %>Yes<%else%>No<%end%>
I was thinking of something like this?
if @item.rigged ? "Yes" : "No"
But it doesn't work. Ruby has the ||= but I"m not even sure how to use that thing.
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
There is also a conditional operator in Ruby, but that is completely unnecessary. The conditional operator is needed in C, because it is an operator: in C, if is a statement and thus cannot return a value, so if you want to return a value, you need to use something which can return a value. And the only things in C that can return a value are functions and operators, and since it is impossible to make if a function in C, you need an operator.
In 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.
BTW: it is customary to name methods which are used to ask a question with a question mark at the end, like this:
@item.rigged?
This shows another problem with using the conditional operator in Ruby:
@item.rigged? ? 'Yes' : 'No'
It's simply hard to read with the multiple question marks that close to each other.
One line if:
<statement> if <condition>
Your case:
"Yes" if @item.rigged
"No" if [email protected] # or: "No" unless @item.rigged
From what I know
3 one-liners
a = 10 if <condition>example:
a = 10 if true # a = 10
b = 10 if false # b = nil
a = 10 unless <condition>example:
a = 10 unless false # a = 10
b = 10 unless true # b = nil
a = <condition> ? <a> : <b>example:
a = true ? 10 : 100 # a = 10
a = false ? 10 : 100 # a = 100
I hope it helps.