2013-08-02 20 views
-1

http://www.ruby-lang.org/en/documentation/他們力提SEEK作爲方法 但在下面的程序中,他們使用'seek'作爲方法?在ruby中是「IO :: SEEK_SET」的一種方法嗎?

input_file = ARGV[0] 
def print_all(f) 
    puts f.read() 
end 
def rewind(f) 
    f.seek(0, IO::SEEK_SET) 
end 
def print_a_line(line_count, f) 
    puts "#{line_count} #{f.readline()}" 
end 
current_file = File.open(input_file) 
puts "First let's print the whole file:" 
puts # a blank line 
print_all(current_file) 
puts "Now let's rewind, kind of like a tape." 
rewind(current_file) 
puts "Let's print three lines:" 
current_line = 1 
print_a_line(current_line, current_file) 
current_line = current_line + 1 
print_a_line(current_line, current_file) 
current_line = current_line + 1 
print_a_line(current_line, current_file) 

回答

1

IO::SEEK_SET是一個常數。所有大小寫的東西通常都是紅寶石常量

::也可以用於方法調用,但這是相當古老的,正在從2.1中刪除ruby(如果我沒記錯的話)。

+0

謝謝Mr.Frederick :) – user2645457

相關問題