Reputation: 36058
I want to know what the counterpart is in Ruby for this kind of expression:
var status=false;
var xx=new Obj(xx,status?"0":"1",status?"2":"3");
I tried the same in Ruby, but it seems that the syntax:
status?"23":nil
does not work.
Upvotes: 1
Views: 85
Reputation: 230461
Put a space between status
and ?
. Seems that it might get parsed as a method name status?
. Also, don't terminate your sentences with semicolons. And don't use var
.
x = status ? "0" : "1"
Upvotes: 2
Reputation: 87486
Method names can end with question marks, so use more spaces:
status ? "23" : nil
Equivalently you could write:
("23" if status)
Upvotes: 3