Ruby: Load Config from YAML if ENV Variables are not set


We are all well aware of the tried and true method of setting your applications variables using ENV, right? Stuff like ENV[‘AWS_KEY’], etc. is a very common way of doing things.

However, there might come a time when it’s either not possible to set those variables, or the whatever. In that case, we can use a YAML file to load them. In this example, we load a YAML file with the variables, and then override them with ENV variables if those have been set. This is a great way to provide a default method, and then have a custom override.