Skip to content

Instantly share code, notes, and snippets.

@cheeyeo
Created May 26, 2014 19:39
Show Gist options
  • Save cheeyeo/32558906f20f88622e55 to your computer and use it in GitHub Desktop.
Save cheeyeo/32558906f20f88622e55 to your computer and use it in GitHub Desktop.
YAML loading in ruby 2.1
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: root
password:
development:
<<: *default
database: db_development
test:
<<: *default
database: db_test
production:
<<: *default
database: db_production
require "yaml"
# config_path = File.expand_path("../config.yml", __FILE__)
# new way in ruby 2.0+
config_path = File.expand_path("config.yml", __dir__)
config = YAML.load_file(config_path)
p config["development"]["database"]
p config["test"]["database"]
p config["production"]["database"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment