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
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。