Using the Ternary Operator : Ternary Operator « Language Basics « Ruby






Using the Ternary Operator


# result = condition ? true_value : false_value

toppings = 4

price = toppings > 3 ? 5.99 : 4.99

 








Related examples in the same category

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