Consider an alternative of Ternary Operator : Ternary Operator « Language Basics « Ruby






Consider an alternative of Ternary Operator


age = 10
type = 'child' if age < 18
type = 'adult' unless age < 18
puts "You are a " + type

 








Related examples in the same category

1.The Ternary Operator: ? :
2.Using the Ternary Operator
3.The ternary operator can be used to build expressions on a single line