Ruby | String insert Method Last Updated : 09 Dec, 2019 Comments Improve Suggest changes Like Article Like Report insert is a String class method in Ruby which is used to inserts the specified string before the character at the given index, modifying the given one. Negative indices count from the end of the string, and insert after the given character. Syntax: str.insert(index, other_str) Parameters: Here, str is the given string. Returns: A modified string. Example 1: ruby # Ruby program to demonstrate # the insert method # Taking a string and # using the method puts "Ruby".insert(0, 'Z') puts "Program".insert(3, 'Z') Output: ZRuby ProZgram Example 2: Ruby # Ruby program to demonstrate # the insert method # Taking a string and # using the method puts "Sample".insert(-4, 'Z') puts "Articles".insert(-5, 'Z') Output: SamZple ArtiZcles Comment More infoAdvertise with us Next Article Ruby | String insert Method K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby String-class Similar Reads Ruby | String inspect Method inspect is a String class method in Ruby which is used to return a printable version of the given string, surrounded by quote marks, with special characters escaped. Syntax: str.inspect Parameters: Returns: Here, str is the given string. Example 1: Ruby # Ruby program to demonstrate # the inspect me 1 min read Ruby | String index Method index is a String class method in Ruby which is used to returns the index of the first occurrence of the given substring or pattern (regexp) in the given string. It specifies the position in the string to begin the search if the second parameter is present. It will return nil if not found. Syntax: s 1 min read Ruby | String center() method center is a String class method in Ruby which is used to centers the given string in width. If the specified width is greater than the length of the given string, then this method will return a new string of the specified width with the given string centered and padded otherwise it returns only give 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 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 Like