How do you loop through a multiline string in Ruby?

alamodey picture alamodey · Mar 2, 2009 · Viewed 30.9k times · Source

Pretty simple question from a first-time Ruby programmer.

How do you loop through a slab of text in Ruby? Everytime a newline is met, I want to re-start the inner-loop.

def parse(input)
    ...
end

Answer

Iraimbilanja picture Iraimbilanja · Mar 2, 2009

String#each_line

str.each_line do |line|
    #do something with line
end