Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

ruby
math
equals
communitycreator

What is eql?() 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 eql?() function returns true if both the source number and number in the parameter are equal; otherwise, it returns false.

Figure 1 shows a visual representation of the eql?() function.

Figure 1: Visual representation of eql?() function

Syntax

num_1.eql?(num_2)
# where num_1 is the number which is to be checked against the num_2 for equality

Parameter

The eql?() function takes another number, num_2, to be compared with num_1 (number).

Return value

The eql?() function returns true if both the numbers are equal; otherwise, it returns false.

Code

#equal numbers
print "(2).eql?(2) : ",(2).eql?(2) , "\n"
print "(2.2).eql?(2.2) : ",(2.2).eql?(2.2) , "\n"
#not equal numbers
print "(3).eql?(2) : ",(3).eql?(2) , "\n"
print "(2.1).eql?(2.2) : ",(2.1).eql?(2.2) , "\n"

RELATED TAGS

ruby
math
equals
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