Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Ruby Conditional Statement Best Practice

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading