Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Loading and parsing YAML files (See related posts)

I use YAML heavily to specify basic configuration options for my applications. Additionally, I have bash scripts to download and parse currency and weather information, which all gets stored as YAML for ease of use.

This is how I parse the YAML into my applications:

require 'yaml'

class ApplicationController < ActionController::Base
  before_filter :configure_app

  # Your code here...

  def configure_app
    @config = YAML::load(File.open("#{RAILS_ROOT}/config/config.yml"))
  end
end

You need to create an account or log in to post comments to this site.


Click here to browse all 4834 code snippets

Related Posts