Hello Everyone, I’m working on a program which is posted below.
Basically my program automates file creating based off arrays at the
beginning of the program. However, I’m unsure of how to do a couple of
things.
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?
Basically this problem repeats itself throughout the entire program
because I’m unsure how to get it to pull from the array! Below, I have
placed stars (*) around all the ‘petpet’ variables that I would like it
to pull from the array and it won’t work, obviously - I just don’t know
how to make it work.
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.
========== PROGRAM BEGIN ===========
$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”]
petpets.each do |petpet|
puts "Now creating file for " + petpet.to_s + “.”
petpet_array = []
colors.each do |color|
url = "http://www.mysite.com/code/" + petpet.to_s + "_" + color.to_s
-
“.gif”
puts url
petpet_array.push urlend
File.open("/Users/superfly/Desktop/news_finder/arrays/" +
petpet.to_s + “_array.yaml”,“w”) do |out|
out << petpet_array.to_yaml
endputs “The file for " + petpet.to_s + " has been created
successfually.”
puts “”
puts “”
end