Home > Software engineering >  Ruby Conditional Statement Best Practice
Ruby Conditional Statement Best Practice

Time:11-01

Sorry for such a naive question but can someone let me know what is the ruby way of writing the below line of code

result.nil? ? false : !result

CodePudding user response:

According to your comment:

  • if result is true then return false
  • if result is false then return true
  • if result is nil then return false

you just need to check for result == false:

result = true
result == false #=> false

result = false
result == false #=> true

result = nil
result == false #=> false
  • Related