Ruby | String chop Method Last Updated : 17 Jun, 2021 Comments Improve Suggest changes Like Article Like Report chop is a String class method in Ruby which is used to return a new String with the last character removed. Both characters are removed if the string ends with \r\n, b. Applying chop to an empty string returns an empty string. Syntax:str.chopParameters: Here, str is the given string.Returns: A new string having no record separator. Example 1: Ruby # Ruby program to demonstrate # the chop method # Taking a string and # using the method puts "Ruby".chop puts "Ruby\r\n".chop Output: Rub Ruby Example 2: Ruby # Ruby program to demonstrate # the chop method # Taking a string and # using the method puts "String\r\n\r\r\n".chop # Removing two characters puts "Method".chop.chop Output: String Meth Comment More infoAdvertise with us Next Article Ruby | String chop Method K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby String-class Similar Reads Ruby | String chop! Method chop! is a String class method in Ruby which is used to return a new String with the last character removed. Both characters are removed if the string ends with \r\n, b. It will return nil if the string is empty. Syntax:str.chop!Parameters: Here, str is the given string.Returns: A new string having 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 chr Method chr is a String class method in Ruby which is used to return a one-character string at the beginning of the string. Syntax:str.chr Parameters: Here, str is the given string. Returns: A one-character string at the beginning of the string. Example 1: Ruby # Ruby program to demonstrate # the chr method 1 min read Ruby | String crypt Method crypt is a String class method in Ruby which is used to returns the string generated by calling crypt(3) standard library function with str and salt_str. Syntax: crypt(salt_str)-> new_str Parameters: Here, str is the given string and salt_str is the specified salt for crypt method. Example 1: Rub 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 hex Method hex is a String class method in Ruby which is used to treats the leading characters from the given string as a string of hexadecimal digits (with an optional sign and an optional 0x) and returns the corresponding number. Zero is returned on error. Syntax: str.hex Parameters: Here, str is the given s 1 min read Ruby | String * Method String# * is a String class method in Ruby which is used to returns a new String containing integer copies of the receiver. Here, integer must be greater than or equal to 0. Syntax: str * Integer Parameters: Here, str is the required string and integer is the number of copies. Returns: This method r 1 min read Ruby | String =~ Method =~() is a String class method in Ruby which is used for matching purpose. If the given object is a Regexp, then this method will use it as a pattern to match against the given string. Syntax: str =~ obj Parameters: Here, str is the given string and obj is the object to be matched. Returns: The posit 1 min read Ruby | String dump Method dump is a String class method in Ruby which is used to generate a version of the given string with all non-printing characters replaced by \nnn notation and all special characters escaped. Syntax: str.dump Parameters: Here, str is the given string. Returns: A new string with all non-printing charact 1 min read Like