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

Source.