File.readlines problem

please run the following program in your computer,the output is
2921
3262
-1
why i can not get:
namefile.puts urlfile.readlines[0…2921]
namefile.puts urlfile.readlines[1…3262]
namefile.puts urlfile.readlines[1…-1]

thinks for telling me the reason.

class Initialcname
def self.down()
require ‘rubygems’
require ‘open-uri’
cname=[‘nasdaq’,‘nyse’,‘amex’]
cname=cname.map{|item|
item=“http://www.nasdaq.com/screening/companies-by-name.aspx?letter=0&exchange="+item+"&render=download”}
open("/tmp/companyname",“a+”) {|namefile|
cname.each.with_index{|url,idx|
open(url){|urlfile|
a=0
while line=urlfile.gets
line=line.chomp
if /<html>/ =~ line then
x=urlfile.lineno-2
a=1
else
end
end
if a==0 then x=-1 end
if idx==0 then
puts x
namefile.puts urlfile.readlines[0…x]
else
puts x
namefile.puts urlfile.readlines[1…x]
end
}
}
}
end
end
Initialcname.down()

i solve it myself,add :
urlfile.rewind
it is ok now

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs