4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/fileutil.rb', line 4
def self.process_file file_path,write
return true unless block_given?
if !File.file? file_path
puts "Not a file: "+file_path
return false
end
file=File.new file_path,"r"
if !file
puts "Failed to read file "+file_path
return false
end
content=""
file.each do |line|
content<<line
end
content=yield content
file.close
return true unless write
file=File.new file_path,"w"
if !file
puts "Failed to write file "+file_path
return false
end
file.write content
file.close
return true
end
|