Open In App

Ruby | Struct == function

Last Updated : 18 Dec, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The == is an inbuilt method in Ruby returns true if other has the same struct subclass and has equal member values.
Syntax: struct1 == 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
# Ruby program for == 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==struct2
puts struct1 == struct2
Output:
true
Example 2: Ruby
# Ruby program for == method in struct 
  
# Include struct
Employee = Struct.new(:company_name, :position, :zip)

#initialise struct
struct1  = Employee.new("GEEK", "INTERN", 12345)
struct2 = Employee.new("geeksforgeeks", "INTERN", 12345)

# Prints the value of struct1==struct2
puts struct1 == struct2
Output:
false

Next Article

Similar Reads