title: How do I parse a YAML file in Ruby?
body: <p>I would like to know how to parse a YAML file with the following contents:</p>
  
  <pre><code>--- 
  javascripts: 
  - fo_global:
    - lazyload-min
    - holla-min
  </code></pre>
  
  <p>Currently I am trying to parse it this way:</p>
  
  <pre><code>@custom_asset_packages_yml = (File.exists?("#{RAILS_ROOT}/config/asset_packages.yml") ? YAML.load_file("#{RAILS_ROOT}/config/asset_packages.yml") : nil)
      if !@custom_asset_packages_yml.nil?
        @custom_asset_packages_yml['javascripts'].each{ |js|
          js['fo_global'].each{ |script|
           script
          }
        }
      end
  </code></pre>
  
  <p>But it doesn't seem to work and gives me an error that the value is nil.</p>
  
  <pre><code>You have a nil object when you didn't expect it!
  You might have expected an instance of Array.
  The error occurred while evaluating nil.each
  </code></pre>
  
  <p>If I try this, it puts out the entire string (fo_globallazyload-minholla-min):</p>
  
  <pre><code>if !@custom_asset_packages_yml.nil?
            @custom_asset_packages_yml['javascripts'].each{ |js|
              js['fo_global']
            }
          end
  </code></pre>