Z
Zoe Phoenix
I'm trying to have Ruby generate a random list of 30 links to put at the
bottom of a web page and write it to a file. I think I'm on the right
track of how to do it, but I'm not sure...
##############
citylist = ['Orlando',
'Tampa',
'Fort Lauderdale',
'Miami',
'St. Petersburg',
'Etc.'
]
output =
30.times do [rand(citylist.length)]
%Q(<a
href="http://www.website.com/cities/website#{rand(citylist.length)}.html">Website
#{rand(citylist.length)}</a> | )
end
File:pen("I:\\My Documents\\Stuff\\More Stuff\\websitelinks.txt", 'w')
do |f|
f.write output
end
##############
I may be mistaken about the use of the block here... Someone please tell
me what I'm doing wrong and how to fix it? The two instances of the
city inside the block should be the same, but I'm not sure how to do
that. Doesn't rand make it a random city each time it's interpreted or
since it's in a block, would it be the same each time the block
repeats..?
bottom of a web page and write it to a file. I think I'm on the right
track of how to do it, but I'm not sure...
##############
citylist = ['Orlando',
'Tampa',
'Fort Lauderdale',
'Miami',
'St. Petersburg',
'Etc.'
]
output =
30.times do [rand(citylist.length)]
%Q(<a
href="http://www.website.com/cities/website#{rand(citylist.length)}.html">Website
#{rand(citylist.length)}</a> | )
end
File:pen("I:\\My Documents\\Stuff\\More Stuff\\websitelinks.txt", 'w')
do |f|
f.write output
end
##############
I may be mistaken about the use of the block here... Someone please tell
me what I'm doing wrong and how to fix it? The two instances of the
city inside the block should be the same, but I'm not sure how to do
that. Doesn't rand make it a random city each time it's interpreted or
since it's in a block, would it be the same each time the block
repeats..?