Ruby | Time <=> method Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The is an inbuilt method in Ruby returns -1, 0, 1 depending on whether time is less than, equal to, or greater than other time. It is returns nil if two times are incomparable. Syntax: time <=> otherTime Parameters: The function accepts no parameter Return Value: It returns -1, 0, 1 depending on whether time is less than, equal to, or greater than other time Example 1: CPP # Ruby code for <=> method # Include Time require 'time' # Declaring time a = Time.new(1993, 02, 24, 12, 0, 0, "+09:00") b = a + (60*60) # Prints -1 puts a <=> b Output: -1 Example 2: CPP # Ruby code for <=> method # Include Time require 'time' # Declaring time a = Time.new(1993, 02, 24, 12, 0, 0, "+09:00") b = a + (60*60) # Prints 1 puts b <=> a Output: 1 Comment More infoAdvertise with us Next Article Ruby | String <=> Method G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Time-class Similar Reads Ruby | String <=> Method <=>() is a String class method in Ruby which is used for comparisons of the strings. This method returns -1, 0, +1, or nil depending on whether the specified string is less than, equal to, or greater than other_string. Syntax: str other_string Parameters: Here, str and other_string are the str 1 min read Ruby | Time + method The + is an inbuilt method in Ruby returns a time after adding given time in seconds Syntax: time + Parameters: The function accepts no parameter Return Value: It returns a time after adding given time in seconds Example 1: CPP # Ruby code for + method # Include Time require 'time' # Declaring time 1 min read Ruby | Date <=>() method Date#<=> is a Date class method which compares two date objects. Syntax: Date<=>b Parameter: Date values Return: 1 if a is greater than b -1 if a is less than b 0 if a equals b Example #1 : Ruby 1=1 # Ruby code for Date.<=>() method # loading date require 'date' # declaring Date a 2 min read Ruby | Date >> method Date#>>() is a Date class method which returns the date object pointing 'n' (numeric value argument) months after self. Syntax: Date.>>() Parameter: Date values Return: date object pointing n months after self. The argument n should be a numeric value. Example #1 : Ruby 1=1 # Ruby code f 2 min read Ruby | Date + method Date#+() is a Date class method which adds a numeric value to the date and returns a date object pointing other days after self. Syntax: Date.+() Parameter: Date values Return: date object pointing other days after self after adding a numeric value to the date. Example #1 : Ruby 1=1 # Ruby code for 2 min read Ruby | Integer >> method The >> is an inbuilt method in Ruby returns the number which is shifted N times to the right. The resultant number is int(num / (2^N)). Syntax: num >> N Parameters: The function accepts no parameter. Return Value: It returns int(num / (2^N)). Example 1: Ruby # Ruby program for >> m 1 min read Like