class File
def self.write filename, content
File.open(filename, 'wb') do |file|
file.write content
end
end
def self.append filename, content
File.open(filename, 'ab') do |file|
file.write content
end
end
def self.expand_path_restricted(file_name, dir_string, restrict_dir_string = nil)
dir_string = expand_path(dir_string)
restrict_dir_string = restrict_dir_string ? expand_path(restrict_dir_string) : dir_string
expanded = expand_path(file_name, dir_string)
unless expanded.index(restrict_dir_string) == 0
raise "Restricted file path #{file_name.inspect} must be inside #{restrict_dir_string.inspect}"
end
expanded
end
end
Ruby中扩展File
最新推荐文章于 2019-09-29 20:38:13 发布