Ruby/File Directory/file handle

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

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

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