設定ファイルをYAMLで読み込み

~/.config-test

# .config-test
# please fill in fields
#
#  name: your-name
#  mail: asdf@jkl.com
#
name: shokai
mail: asdf@jkl.com


~/.config-yamlを読む、無ければテンプレートを作る

require 'yaml'

@@template  = <<EOF
# .config-test
# please fill in fields
#
#  name: your-name
#  mail: asdf@jkl.com
#
name: 
mail: 
EOF


home = ENV['HOME'] || ENV['USERPROFILE'] || ENV['HOMEPATH']

begin
  config = YAML::load open(home + "/.config-test")
rescue
  open(home + '/.config-test','w').write(@@template)
end

if config['name'] == nil || config['mail'] == nil
  puts 'Error! Please edit ~/.config-test'
  exit(0)
end

config.each{ |key,value|
  puts key + "=" + value
}


実行してみる
ruby config-test.rb

name=shokai
mail=asdf@jkl.com

参考

-