Ruby is an open-sourced object-oriented programming language developed by Yukihiro Matsumoto. In Ruby, everything is treated as an object. true, false and nil are built-in data types of Ruby.
Note: Always remember in Ruby true, false, and nil are objects, not numbers. Whenever Ruby requires a Boolean value, then nil behaves like false and values other than nil or false behave like true.
True and False
In Ruby, true and false are boolean values that represent yes and no. true is an object of TrueClass and false is an object of FalseClass.
Note: Ruby does not contain Boolean class.
Let’s see a few examples of true and flase in Ruby.
True! a and b are equal
In Ruby, nil is a special value that denotes the absence of any value. Nil is an object of NilClass. nil is Ruby’s way of referring to nothing or void. Ruby also provide a nil? method to detect if any object is nil or not.
- How to check pointer or interface is nil or not in Golang?
- false command in Linux with examples
- How to append class if condition is true in Haml?
- Similarities and Differences between Ruby and C language
- Similarities and Differences between Ruby and C++
- Ruby | Exception Class and its Methods
- Ruby | Dir Class and its methods
- Ruby | unless Statement and unless Modifier
- Ruby Break and Next Statement
- Ruby Date and Time
- Ruby redo and retry Statement
- Ruby Search and Replace
- BEGIN and END Blocks In Ruby
- Catch and Throw Exception In Ruby
- Ruby getters and setters Method
- Ruby | Class Method and Variables
- Difference Between Laravel and Ruby on Rails