From: Brian Candler Date: 2011-08-13T20:13:27+09:00 Subject: Re: Stuck at an Issue with OptParse and File IO ideal one wrote in post #1016461: > Hi, > i am picking default values that i am using in optparser class, > something like this... > > options.logfile = LOGFILE > options.results_dir = Pathname.new(ENV['TEMP']) > > PROG = Pathname.new($0).basename > EFIX = PROG.sub(/\..*$/,'') > LOGFILE = Pathname.new("#{ENV['TEMP']}/#{FPREFIX}.log") That code wouldn't work, because you're using LOGFILE (in the first line) before you've assigned to it (the last line); and also you've not shown any initial creation of the 'options' object anyway. So the best thing you can do is to write a single, complete, standalone program which demonstrates your problem - then it's easy for us to run it and explain what's wrong. Although usually, I think you'll find that in the process of boiling it down to this test case, you'll work out what the problem was anyway. > fh = options.logfile.open('w') --> This line is failing > log = TeeLogger.new(fh,$stderr) > log.level = Logger::INFO > log = TeeLogger.new(fh,$stderr) > > > Im running it on eclipse and on also on cmd i get the same error....So > when i run=> > ruby opttest.rb > > "C:/Users/user1/workspace/Test/opttest.rb:153:in `
': undefined > method `logfile' for # (NoMethodError) That means: your 'options' object, which is an instance of class OptionParser, doesn't have a method called 'logfile'. So you need to go to the documentation for OptionParser and see what method you should be calling instead. -- Posted via http://www.ruby-forum.com/.