Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. 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.3 · 3.2 · 3.1 · 3.0