output.rb
open("./output.txt", "r+") do |file|
# insert current time to head line
lines = file.readlines
lines.unshift("hello\n")
file.rewind
lines.each do |line|
file.write line
end
end
なんかもっといい手がありそう。
More than 5 years have passed since last update.
open("./output.txt", "r+") do |file|
# insert current time to head line
lines = file.readlines
lines.unshift("hello\n")
file.rewind
lines.each do |line|
file.write line
end
end
なんかもっといい手がありそう。
Register as a new user and use Qiita more conveniently