def foo
  while true
    lines = []
    while gets
      break if $_ =~ /^\n/
      lines << $_.split('').map(&:to_i)
      break if lines.size == 8
    end

    next if $_ =~ /^\n/
    break if $_.nil?

  end
end

foo