Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

ruby
communitycreator

What is num.zero? in Ruby?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The num.zero? function returns true if the number is zero, and false otherwise.

Figure 1: Visual representation of the num.zero? function

Syntax

num.zero?
# where num is the number which is to be checked for zero

Parameter

This function does not require a parameter.

Return value

This function returns true if the number is zero. Otherwise, it returns false.

Code

#zero number
print "(0).zero? : ",(0).zero? , "\n"
print "(0.0).zero? : ",(0.0).zero? , "\n"
#non-zero number
print "(4).zero? : ", (4).zero?, "\n"
print "(4.5).zero? : ", (4.5).zero?, "\n"

RELATED TAGS

ruby
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring