title: How do I turn a string into the name of an array?
body: <p>I've think I've created multiple arrays from strings but if I try to inspect the array I receive an error.</p>
  
  <pre><code>File.open("livestock.txt", "r") do |file|
      file.readlines.each do |x|
  
          if x.match(/:*:/)
              # puts x.inspect
              # strip string
              x.gsub!(/[^A-Za-z]/, '')
              x.downcase!
              puts x.inspect
              x = Array.new(){Hash.new}
              # puts x.inspect
              pigs.inspect
          else
              # puts "no"
          end
  
      end
  end
  
  
  animals.rb:12:in `block (2 levels) in &lt;main&gt;': undefined local variable or method `pigs' for main:Object (NameError)
      from animals.rb:2:in `each'
      from animals.rb:2:in `block in &lt;main&gt;'
      from animals.rb:1:in `open'
      from animals.rb:1:in `&lt;main&gt;'
  </code></pre>
  
  <p>Ideally I want to create pigs =[]
  then add hashes to this array such as:</p>
  
  <pre><code>pigs = [{"name"=&gt;"peggy", "id"=&gt;1, "owner"=&gt;"wolcott farms"},
  {"name"=&gt;"sue", "id"=&gt;2, "owner"=&gt;"blue moon farms"},
  {"name"=&gt;"eddie", "id"=&gt;3, "owner"=&gt;"sunrise farms"}
  ]
  </code></pre>
  
  <p>and the same for cows, etc.</p>
  
  <p>my text file animals.txt is </p>
  
  <pre><code>::pigs::  
  name, id, owner
  peggy, 1, wolcott farms 
  sue, 2, blue moon farms
  eddie, 3, sunrise farms
  
  ::cows:: 
  name, id, owner 
  dee, 3, black hat farms 
  sunny, 2, blue moon farms 
  bess, 4, wolcott farms
  </code></pre>