<=>() 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 strings which are compared.
Returns: Returns nil if the two specified values are incomparable.
Note: The longer string is considered greater than the shorter one if the specified strings are of different lengths, and the strings are equal when compared up to the shortest length,
- Ruby | String * Method
- Ruby | String hex Method
- Ruby | String chr Method
- Ruby | String == method
- Ruby | String =~ Method
- Ruby | String eql? Method
- Ruby | String << Method
- Ruby | String + Method
- Ruby | String === Method
- Ruby | String bytesize method
- Ruby | String ascii_only? Method
- Ruby | String chop! Method
- Ruby | String delete_suffix Method
- Ruby | String chomp! Method
- Ruby | String each_line Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.