From: Farrel Lifson Date: 2006-06-24T00:07:49+09:00 Subject: Re: Warning message about "initialized constant" On 23/06/06, Peter Bailey wrote: > This is part of a script I use that simply ftps a bunch of files over to > a UNIX server at my company. It does work, but, I keep getting a warning > message from RUBY about "rb:20:warning: already initialized constant > BWDFile". The line 20 it's referring to is my line 5 below. > > Thanks for any help. > ----------------------------------------------------------------------------------- > ... > 1 ftp = Net::FTP.open('quark.bna.com') do |ftp| > 2 ftp.login('xxxxxx','xxxxxxxx') > 3 ftp.chdir('/xxxxx/xxx/xxd/xxxx') > > 4 BWDFiles=Dir.glob("*.{pdf,gif}") > 5 BWDFiles.each do |BWDFile| > 6 ftp.putbinaryfile(BWDFile) > 7 FileUtils.rm(BWDFile) > 8 end > 9 end > > -- > Posted via http://www.ruby-forum.com/. > > Variable names beginning with uppercase are treated as constants by the Ruby interpreter. In the first iteration of the each loop the line: BWDFiles.each do |BWDFile| assigns to BWDFile the first element of BWDFiles. In the next iteration it tries to set BWDFiles to the second element but because BWDFile is a constant it generates the warning. Farrel