↖️ Show all posts

Reading Yaml Config Files for Ruby Scripts

Again, Ruby makes this easy as pie.

# config.yml
user_data: hello world
level_one:
  level_two: level two world
# config.rb
require 'yaml'

config = YAML.load_file('./config.yml')
puts config['user_data']
# => 'hello world'
puts config['level_one']['level_two']
# => 'level two world'
puts config['level_one']
# => {"level_two" => "level two world"}

⬅️ Read previous Read next ➡️