Ruby | String each_line Method Last Updated : 12 Dec, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 record separator is supplied, Syntax: str.each_line(separator=$/ [, getline_args]) Parameters: Here, str is the given string. Returns: An enumerator if the no block is given. Otherwise the splitted string. Example 1: Ruby # Ruby program to demonstrate # the each_line method # Taking a string and # using the method puts "Ruby\nString".each_line {|s| p s} Output: "Ruby\n" "String" Ruby String Example 2: Ruby # Ruby program to demonstrate # the each_line method # Taking a string and # using the method puts "Sample\nInput".each_line {|s| p s} Output: "Sample\n" "Input" Sample Input Comment More infoAdvertise with us Next Article Ruby | String each_str Method K Kirti_Mangal Follow Improve Article Tags : Ruby Ruby-Methods Ruby String-class Similar Reads 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 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 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 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 insert Method 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 1 min read Ruby | String delete() Method delete is a String class method in Ruby which is used to return a copy of the given string with all characters in the intersection of its arguments deleted. Syntax: str.delete(parameter_list) Parameters: Here, str is the given string and parameter_list are the specified characters. Returns: A new co 1 min read Like