I'll add that in order to use ARGF
with parameters, you need to clear ARGV
before calling ARGF.each
. This is because ARGF
will treat anything in ARGV
as a filename and read lines from there first.
Here's an example 'tee' implementation:
File.open(ARGV[0], 'w') do |file|
ARGV.clear
ARGF.each do |line|
puts line
file.write(line)
end
end