🖥

#Ruby - Tempfile write rewind close unlink – lifecycle

2020/01/26に公開
tempfile = Tempfile.new
# => #<File:/var/folders/nt/brt3bhdn50v57vqgz5t6xqc40000gn/T/20200125-67882-1mn35v6>

tempfile.write('ABC')
# => 3

tempfile.read
# => ""

File.read(tempfile.path)
# => "ABC"

tempfile.rewind
# => 0

tempfile.read
# => "ABC"

tempfile.close
# => nil

File.read(tempfile.path)
# => "ABC"

tempfile.read
# IOError: closed stream
# from /Users/yumainaura/.rbenv/versions/2.5.3/lib/ruby/2.5.0/delegate.rb:349:in `read'

tempfile.unlink
# => true

File.read(tempfile.path)
# TypeError: no implicit conversion of nil into String

Original by Github issue

https://github.com/YumaInaura/YumaInaura/issues/2964

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2020-01-26

Discussion