Create class to wrap File.exist and File.new method : exist « File Directory « Ruby






Create class to wrap File.exist and File.new method


class MyFile
  attr_reader :handle

  def initialize(filename)
    if File.exist?(filename)
      @handle = File.new(filename, "r")
    else
      return false
    end
  end
end

 








Related examples in the same category

1.Checking If a File Exists
2.Checking to See if a File Exists
3.Check to see if a dicectory exists