Ruby 结构体 ==
函数
在Ruby中, ==
是一个内置的方法,如果其他的结构子类有相同的成员值,则返回真。
语法 :struct1 == struct2
参数 :该函数不接受任何参数。
返回值 :如果两个给定的范围相等,则返回布尔值 “true”,否则返回 “false”。
示例 1 :
# 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
输出:
true
例2 :
# 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
输出:
false