Ruby use Yaml

October 28, 2019

Sometimes I need to create a ruby project as a proof of concept, and it is good practive to secrets in a yaml file not checked into git.

Here is a snippet of code that easily allows you import yaml:

require 'yaml'

cnf = YAML::load(File.open('config.yml'))

secret = cnf['example']['secret']

Now create a config.yml:

example:
  secret: 'abc123'

Just make sure to update your .gitingnore file to have the following”

config.yml

Search