Skip to content

Instantly share code, notes, and snippets.

@lhm
Created May 9, 2016 13:06
Show Gist options
  • Save lhm/7c89ac1ddef30ba27b54910eaa143c8b to your computer and use it in GitHub Desktop.
Save lhm/7c89ac1ddef30ba27b54910eaa143c8b to your computer and use it in GitHub Desktop.
inifile quoting
File contents:
[one]
key = value; with semicolon
quoted = "quoted value; with semicolon"
escaped = value\; with escaped semicolon
next = value
Parsed contents:
{"key"=>"value", "quoted"=>"quoted value; with semicolon", "escaped"=>"valuenext = value"}
Second write file contents:
[one]
key = value
quoted = quoted value; with semicolon
escaped = valuenext = value
Parsed contents:
{"key"=>"value", "quoted"=>"quoted value", "escaped"=>"valuenext = value"}
require 'inifile'
data = {
'key' => 'value; with semicolon',
'quoted' => '"quoted value; with semicolon"',
'escaped' => 'value\; with escaped semicolon',
'next' => 'value'
}
ini = IniFile.new filename: 'my.cfg'
ini['one'] = data
ini.save
puts 'File contents:'
puts File.read('my.cfg')
ini = IniFile.load 'my.cfg'
puts 'Parsed contents:'
puts ini['one']
puts
ini.save
puts 'Second write file contents:'
puts File.read('my.cfg')
ini = IniFile.load 'my.cfg'
puts 'Parsed contents:'
puts ini['one']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment