Tracks
/
Ruby
Ruby
/
Syllabus
/
Booleans
Bo

Booleans in Ruby

13 exercises

About Booleans

True, False

  • true and false are used to represent boolean logical states.
    • They are singleton instances of the TrueClass and FalseClass objects.
    • they may occur as literals in code, or as the result of logical (&&, ||, !) or comparison (<, >, ==) methods.

Truthy and falsey

  • When not using strict Boolean values, truthy and falsey evaluation rules are applied:

    • Only false and nil evaluates as falsey.
    • Everything else evaluates as truthy.
    # A simplified definition
    def falsey
      nil || false
    end
    
    def truthy
      not falsey
    end
    
Edit via GitHub The link opens in a new window or tab

Learn Booleans