Ruby | String casecmp Method Last Updated : 08 Jan, 2020 Comments Improve Suggest changes Like Article Like Report casecmp is a String class method in Ruby which is Case-insensitive version of String#<=>. For now, case-insensitivity only works on characters A-Z/a-z, not all of the Unicode characters. This method is different from casecmp! method. Syntax: str.casecmp(other_str) Parameters: Here, str is the given string to be checked and other_str is the string to which str is compared. Returns:This method will returns the true or false based on the equality of the str and other_str. It can also return nil if the two strings have incompatible encodings, or if other_str is not a string. Example 1: Ruby # Ruby program to demonstrate # the casecmp method # Taking a string and # using the method puts "RuBy".casecmp("ruby") puts "GeeksforGeeks".casecmp("gfg") Output: 0 -1 Example 2: Ruby # Ruby program to demonstrate # the casecmp method # Taking a string and # using the method # here it will give nil puts "\u{e5 f6 dc}".encode("ISO-8859-1").casecmp("\u{c4 d4 de}") puts "GFG".casecmp("250") Output: 1 Comment More infoAdvertise with us Next Article Ruby | String casecmp Method K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby String-class Similar Reads Ruby | String casecmp? Method casecmp? is a String class method in Ruby which is used to return true if both the string are equal after Unicode case folding and false if they are not equal. Syntax: str.casecmp?(other_str) Parameters: Here, str is the given string to be checked and other_str is the string to which str is compared 1 min read Ruby | String chars() Method chars is a String class method in Ruby which is used to return an array of characters in str. Syntax: str.chars Parameters: Here, str is the given string Returns: An array of the characters. Example 1: Ruby # Ruby program to demonstrate # the chars method # Taking a string and # using the method put 1 min read Ruby | String chomp! Method chomp! is a String class method in Ruby which is used to returns new String with the given record separator removed from the end of str (if present). chomp method will also removes carriage return characters (that is it will remove \n, \r, and \r\n) if $/ has not been changed from the default Ruby r 1 min read Ruby | String chomp Method chomp is a String class method in Ruby which is used to returns new String with the given record separator removed from the end of str (if present). chomp method will also remove carriage return characters (that is it will remove \n, \r, and \r\n) if $/ has not been changed from the default Ruby rec 1 min read Ruby | String hash method hash is a String class method in Ruby which is used to return a hash based on the string's length, content and encoding. Syntax: str.hash Parameters: Here, str is the given string. Returns: A hash based on the string's length, content and encoding. Example 1: Ruby # Ruby program to demonstrate # the 1 min read Like