ruby conditional operator ? :

Y

Yaxm Yaxm

Hi,
in java, I can use ? : shorthand operators to ensure s is assigned to
some value.
String s = s == null ? "" : s;

Is there similar shorthand operator in Ruby?

Thanks.
Yaxm
 
J

John Joyce

Hi,
in java, I can use ? : shorthand operators to ensure s is assigned to
some value.
String s = s == null ? "" : s;

Is there similar shorthand operator in Ruby?

Thanks.
Yaxm

The same old ternary operator is in Ruby as in most languages these
days.
? :
so...

conditional_statement ? true_result : false_result
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,241
Messages
2,571,219
Members
47,850
Latest member
StewartTha

Latest Threads

Top