Ruby 1.9.3 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > ARGF.classクラス > closed?
closed? -> bool[permalink][rdoc]ARGFがcloseされていればtrueを返します。
# カレントディレクトリから適当にファイルを選ぶ
ARGV.replace(
Dir.glob("*").reject{|name| FileTest.file?(name) == false}
)
ARGF.each {|line|
p [ line.chomp, ARGF.filename ]
ARGF.close
if ARGF.closed?
p "ARGF is closed."
else
p "ARGF is not closed"
end
}
if ARGF.closed?
p "ARGF had been closed."
else
p "ARGF is not closed"
end
#例
#=> ["cat:", "sample.yaml"]
#=> "ARGF is not closed"
#=> ["", "test.rb"]
#=> "ARGF is not closed"
#=> ["--- !ruby/object:Dog ", "ugo.yaml"]
#=> "ARGF is closed."
#=> "ARGF had been closed."
[SEE_ALSO] IO#closed?