Ruby | String chars() Method Last Updated : 17 Dec, 2019 Comments Improve Suggest changes Like Article Like Report 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 puts "Ruby String".chars() puts "Methods".chars() Output: R u b y S t r i n g M e t h o d s Example 2: Ruby # Ruby program to demonstrate # the chars method # Taking a string and # using the method puts "GFG".chars() puts "G4G".chars() Output: G F G G 4 G Comment More infoAdvertise with us Next Article Ruby | String chars() Method K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby String-class Similar Reads 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 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 Ruby| String Clear Method clear is a String class method in Ruby which is used to make the string empty. Syntax: str.clear Parameters: Here, str is the given string. Return : An empty string. Example 1: Ruby # Ruby program to demonstrate # the clear method # Taking a string and # using the method puts "String".clea 1 min read 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 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. Applying chop to an empty string returns an empty string. Syntax:str.chopParameters: Here, str is the given string.Returns: A new 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 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 casecmp Method 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 1 min read 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 Like