The Ternary Operator: ? : : Ternary Operator « Language Basics « Ruby






The Ternary Operator: ? :


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

 








Related examples in the same category

1.Consider an alternative of Ternary Operator
2.Using the Ternary Operator
3.The ternary operator can be used to build expressions on a single line