Ruby 2.7.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > File::Statクラス > size?
size? -> Integer | nil
[permalink][rdoc]サイズが0の時にはnil、それ以外の場合はファイルサイズを返します。
require 'tempfile'
fp = Tempfile.new("temp")
p fp.size #=> 0
p File::Stat.new(fp.path).size? #=> nil
fp.print "not 0 "
fp.close
p FileTest.exist?(fp.path) #=> true
p File::Stat.new(fp.path).size? #=> 6