Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

ARGF#file

ARGF.file → IO or File object

Returns the current file as an IO or File object. $stdin is returned when the current file is STDIN.

For example:

$ echo "foo" > foo
$ echo "bar" > bar

$ ruby argf.rb foo bar

ARGF.file      #=> #<File:foo>
ARGF.read(5)   #=> "foo\nb"
ARGF.file      #=> #<File:bar>
See also #external_encoding #filename #eof? #fileno also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1