Using YAML data in Ruby App
<p>I want to load data from my YAML file and use the it in my ruby application. The contents available in YAML will be used in different places. Therefore, I want to read it initially and use the data whenever required.</p>

<p>I would like to know what is the best practice for this?</p>

<p>What I tried is</p>

<p>config.yaml</p>

<pre><code>db:
 username: admin
 password: admin
</code></pre>

<p>config.rb</p>

<pre><code>class Config
 class &lt;&lt; self
    attr_accessor :uname, :pwd
    def load
       config_data = YAML.load_file("c:\config.yml")
       @uname = config_data['db']['username']
       @pwd = config_data['db']['password']
    end
 end
end
</code></pre>

<p>my_app.rb</p>

<pre><code>Config.load
puts Config.uname
puts Config.pwd
</code></pre>

<p>Please let me know whether this is a right way to load and use YAML data. If not please share the best practice.</p>