Created
May 9, 2016 13:06
-
-
Save lhm/7c89ac1ddef30ba27b54910eaa143c8b to your computer and use it in GitHub Desktop.
inifile quoting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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