Pemula Exercism • ruby

Booleans

Ringkasan Pelajaran

# Introduction

About

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

Originally from Exercism ruby concepts