Ruby/File Directory/file handle

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

(Различия между версиями)
Перейти к: навигация, поиск

Версия 17:10, 26 мая 2010

assign the file handle to a class or instance variable:

class MyFile
  attr_reader :handle
  def initialize(filename)
    @handle = File.new(filename, "r")
  end
  def finished
    @handle.close
  end
end
f = MyFile.new("text.txt")
puts f.handle.gets
f.finished