Ruby/Development/ARGF

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

ARGF.gets

#!/usr/bin/env ruby
while line = ARGF.gets
 puts line
end



ARGF ($

while line = ARGF.gets
 print line
end



ARGV and ARGF

ARGV << "myFile.txt"
print while gets
# ARGV (or $*) is an array, and each of its elements is a filename submitted on the command line. 
# You can apply any method to ARGV that you might apply to any other array. 
 
p ARGV # => ["sonnet_119.txt"]
# or:
ARGV#[0] # => ["sonnet_119.txt"]