ファイルを解析し、rubyのいくつかのヘッダー文字列を削除したいと思います。
解析されるファイルは次のようになります。
---
some
text
text2
string
and
so
on
---
another string
and the other
そして削除したい
---
some
text
text2
string
and
so
on
---
この部分。
編集:私はこのようなルビーコードを書きました
file = File.open("test")
a = file.readlines
skip = 0
a.each do |line|
if line.match("---\n")
if skip == 1
skip-=1
else
skip+=1
end
else
if skip != 1
print line
end
end
end
これは機能しますが、私のコードは汚れているので、クリーンアップする必要があると思います。コードを単純化するにはどうすればよいですか?