def File.open_as_string(name, mode = "")
unless block_given?
raise(ArgumentError, "Need to supply block to File.open_as_string")
end
if mode.is_a?(Numeric) then
flag, mode = mode, ""
mode += "b" if flag & File::Constants::BINARY != 0
mode += "+" if flag & File::Constants::APPEND != 0
else
mode.delete!("^b+")
end
str = File.open(name, "r#{mode}") { |file| file.read }
old_str = str.clone
begin
yield str
ensure
if old_str != str then
File.open(name, "w#{mode}") { |file| file.write(str) }
end
end
end