Created
May 26, 2014 19:39
-
-
Save cheeyeo/32558906f20f88622e55 to your computer and use it in GitHub Desktop.
YAML loading in ruby 2.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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