From: Robert Klemme Date: 2008-06-25T18:19:30+09:00 Subject: Re: Creating a variable based on array 2008/6/25 Tj Superfly : > The line 'petpet_array = []' obviously doesn't work because it just > thinks "petpet_array", but I need it to use the item coming from the > array, so how might I be able to accomplish that? I am not sure what you mean here. Of course you can initialize the local variable in every loop - and you get a new Array. > Basically this problem repeats itself throughout the entire program > because I'm unsure how to get it to pull from the array! "pull from the array"? I have no idea what that is supposed to mean in this context. > If anyone can help me out with this, instruct me how to get it to do > what I'm wanting, please let me know. If you have questions, please > post. :) This is how I'd probably do it: basically you just need Array#map, i.e. you create a new Array from the values in color. Here's how I'd do it: #!/bin/env ruby require 'yaml' $defout.sync=true petpets = ["Slorg", "Sludgy", "Spyder", "Wadjet", "Buzzer", "Angelpuss", "Mallard", "Scarabug", "Cobrall", "Magaral", "Tenna", "Floud", "Slymook", "Stego", "Selket", "Warf", "Altachuck", "Khnum", "Blobagus", "Tomamu", "Psimouse", "Puppyblew", "Hopso", "Harris"] colors = ["black", "blue", "brown", "chocolate", "christmas", "clay", "cloud", "custard", "darigan", "disco", "dung", "faerie", "fire", "ghost", "glow", "gold", "green", "grey", "halloween", "ice", "invisible", "island", "jelly", "maraquan", "mutant", "orange", "pink", "pirate", "plushie", "purple", "rainbow", "red", "robot", "sketch", "snow", "spotted", "starry", "tyrannian", "white", "yellow"] base = "/Users/superfly/Desktop/news_finder/arrays" petpets.each do |petpet| puts "Now creating file for #{petpet}." array = colors.map do |color| "http://www.mysite.com/code/#{petpet}_#{color}.gif" end puts array File.open("#{base}/#{petpet}_array.yaml","w") do |out| YAML.dump(array, out) end puts "The file for #{petpet} has been created successfully.", "", "" end Note that String interpolation (using #{} inside double quoted Strings) is usually faster and - as you can see - takes up less space in the program because it does #to_s implicitly. Another note: you can make your life a bit easier by using %w{} to generate all those arrays, i.e. petpets = %w{Slorg Sludgy Spyder Wadjet} # etc This works only if your words do not contain whitespace which seems to be the case here. Kind regards robert -- use.inject do |as, often| as.you_can - without end