入出力でも考え込む

−入出力にはIOクラスまたはそのサブクラスのオブジェクトが使われます。IOオブジェクトは関数openで作ることができます。− by Ruby本 P.85

file = File.open("test.txt")
=> #
file.close
=> nil
file
=> #
もうまくいったし

file = File.new("test.txt")
=> #
file.close
=> nil
file
=> #
でもうまくいった。でも
File.open("test.txt")
=> #
File.close
NoMethodError: undefined method `close' for File:Class
では閉じれないし
File.new("test.txt")
=> #
File.close
NoMethodError: undefined method `close' for File:Class
でも閉じれなかった。IOクラスでは
IO.open("test.txt")
TypeError: cannot convert String into Integer
でも
IO.new("test.txt")
TypeError: cannot convert String into Integer
でもうまくいかず
IO.new(1)
=> #
IO.close
NoMethodError: undefined method `close' for IO:Class
で閉じれなかった。また

file = IO.new(1)
=> #
としたら

file.close
in `write': Bad file descriptor (Errno::EBADF)
こんなんでました。きっとはちゃめちゃやってるんでしょうね。