If I do:
require \'inifile\'
# read an existing file
file = IniFile.load(\'~/.config\')
data = file[\'profile\'] # error here
puts data[\'region\']
When given ~
in a path at the command line, the shell converts ~
to the user's home directory. Ruby doesn't do that.
You could replace ~
using something like:
'~/.config'.sub('~', ENV['HOME'])
=> "/Users/ttm/.config"
or just reference the file as:
File.join(ENV['HOME'], '.config')
=> "/Users/ttm/.config"
or:
File.realpath('.config', ENV['HOME'])
=> "/Users/ttm/.config"