title: Extracting data from yml files with ruby
body: <p>I read some quick tutorials on Yaml or yml file format. I made a yaml document to represent my data. I saw some ruby tutorials which tell you how to extract yaml with ruby. Unfortunately, they just print the whole data or just keys and values. It does not meet my needs. Please help.</p>
  
  <p>yaml file -</p>
  
  <pre><code>dev:
    game1:
      server1:
          url: 'dev-game1-a-srv01.gamer.com'
          log-path: '/srv/logs'
      server2:
          url: 'dev-game1-a-srv02.gamer.com'
          log-path: '/srv/logs'
  
    game2:
      server1:
          url: 'dev-game2-a-srv01.gamer.com'
          log-path: '/srv/logs'
      server2:
          url: 'dev-game2-b-srv02.gamer.com'
          log-path: '/srv/logs'
      server3:
          url: 'dev-game2-b-srv01.gamer.com'
          log-path: '/srv/logs'
  prod: 
  etc....
  </code></pre>
  
  <p>How do I select dev, game2, server 3, url using ruby code ?</p>
  
  <p>Using the code below, I get an exception - </p>
  
  <pre><code>require 'yaml'
  
  def server_info
      path = 'C:\Code\demo-srv.yml'
      yml = YAML::load(File.open(path))
      game2 = yml['dev']['game2'] 
      game2.each{|server|
          if server['server3']
              puts server['server3']['url']
          end
      }
  end
  
  server_info
  </code></pre>
  
  <p>error - </p>
  
  <pre><code>server.rb:8:in `[]': can't convert String into Integer (TypeError)
          from server.rb:8:in `server_info'
          from server.rb:7:in `each'
          from server.rb:7:in `server_info'
          from server.rb:14
  </code></pre>