Open In App

Ruby | Struct eql?() function

Improve
Improve
Like Article
Like
Save
Share
Report

The eql?() is an inbuilt method in Ruby returns true if other has the same struct subclass and has equal member values.

Syntax: struct1.eql?(struct2)

Parameters: The function accepts no parameter.

Return Value: It returns boolean value true if both the given ranges are equal, else it returns false.

Example 1:




# Ruby program for eql? method in struct 
    
# Include struct
Employee = Struct.new(:company_name, :position, :zip)
  
#initialise struct
struct1  = Employee.new("GEEK", "INTERN", 12345)
struct2 = Employee.new("GEEK", "INTERN", 12345)
  
# Prints the value of struct1.eql?(struct2)
puts struct1.eql?(struct2)


Output:

true

Example 2:




# Ruby program for eql? method in struct 
    
# Include struct
Employee = Struct.new(:company_name, :position)
  
#initialise struct
struct1  = Employee.new("GEEK", "INTERN")
struct2 = Employee.new("Data structure", "INTERN")
  
# Prints the value of struct1.eql?(struct2)
puts struct1.eql?(struct2)


Output:

false

Last Updated : 06 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads