Override file open method : File class « File Directory « Ruby






Override file open method


class File 
    def File.open(*args) 
        result = f = File.new(*args) 
        if block_given? 
            begin 
                result = yield f 
            ensure 
                f.close 
            end 
        end 
        return result 
    end 
end 

 








Related examples in the same category

1.Add class method to File class