Ruby - String split() Method with Examples Last Updated : 03 Jul, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report split is a String class method in Ruby which is used to split the given string into an array of substrings based on a pattern specified. Here the pattern can be a Regular Expression or a string. If pattern is a Regular Expression or a string, str is divided where the pattern matches. Syntax: arr = str.split(pattern, limit) public Parameters: arr is the list, str is the string, pattern is the either string or regExp, and limit is the maximum entries into the array. Returns: Array of strings based on the parameters. Example 1: ruby # Ruby program to demonstrate split method # Split without parameters # Here the pattern is a # single whitespace myArray = "Geeks For Geeks".split puts myArray Output: Geeks For Geeks Example 2: ruby # Ruby program to demonstrate split method # Here pattern is a regular expression # limit value is 2 # / / is one white space myArray = "Geeks For Geeks".split(/ /, 2) puts myArray Output: Geeks For Geeks Example 3: ruby # Ruby program to demonstrate split method # Here the pattern is a regular expression # limit value is -1 # if the limit is negative there is no # limit to the number of fields returned, # and trailing null fields are not # suppressed. myArray = "geeks geeks".split('s', -1) puts myArray Output: geek geek Comment More infoAdvertise with us Next Article Ruby - String split() Method with Examples G Ganeshchowdharysadanala Follow Improve Article Tags : Ruby Ruby-Methods Ruby-String Similar Reads Ruby | String each_str Method each_str is a String class method in Ruby which is used to passes each character in the given string to the given block, or returns an enumerator if no block is given. Syntax: str.each_byte Parameters: Here, str is the given string. Returns: An enumerator. Example 1: Ruby # Ruby program to demonstra 1 min read Ruby | String each_line Method each_line is a String class method in Ruby which is used to split the given string sing the supplied parameter as the record separator ($/ by default), passing each substring in turn to the supplied block. The string is split into paragraphs delimited by multiple successive newlines if a zero-length 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 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 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 Like