The ternary operator can be used to build expressions on a single line : Ternary Operator « Language Basics « Ruby






The ternary operator can be used to build expressions on a single line


age = 10
puts "You are a " + (age < 18 ? "child" : "adult")

 








Related examples in the same category

1.The Ternary Operator: ? :
2.Consider an alternative of Ternary Operator
3.Using the Ternary Operator