红宝石 |时间 eql?()函数
eql?()是 Ruby 中的一个内置方法,如果时间和其他时间都是具有相同秒数和小数秒数的时间对象,则返回 true,否则返回 false
Syntax: time.eql?()
Parameters: The function accepts no parameter
Return Value: It returns true if time and other time are both time objects with the same seconds and fractional seconds otherwise false
示例 1 :
# Ruby code for eql?() method
# Include Time
require 'time'
# Declaring time
a = Time.new(2000, 12, 23, 9, 3, 3.0)
b = Time.new(2000, 12, 23, 9, 3, 3.0)
# Prints boolean value
puts a.eql?(b)
输出:
true
示例 2 :
# Ruby code for eql?() method
# Include Time
require 'time'
# Declaring time
a = Time.new(2000, 12, 23, 9, 3, 3.0)
b = Time.new(2000, 12, 23, 9, 3, 4.0)
# Prints boolean value
puts a.eql?(b)
输出:
false