Method: IniFile#write
- Defined in:
- lib/inifile.rb
#write(opts = {}) ⇒ Object Also known as: save
Public: Write the contents of this IniFile to the file system. If left unspecified, the currently configured filename and encoding will be used. Otherwise the filename and encoding can be specified in the options hash.
opts - The default options Hash
:filename - The filename as a String
:encoding - The encoding as a String (Ruby 1.9)
Returns this IniFile instance.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/inifile.rb', line 105 def write( opts = {} ) filename = opts.fetch(:filename, @filename) encoding = opts.fetch(:encoding, @encoding) mode = (RUBY_VERSION >= '1.9' && encoding) ? "w:#{encoding.to_s}" : 'w' File.open(filename, mode) do |f| @ini.each do |section,hash| f.puts "[#{section}]" hash.each {|param,val| f.puts "#{param} #{@param} #{escape_value val}"} f.puts end end self end |