> > James, > > Try reading the RubyGarden wiki page WhatIsAnObject[0] and Allen Holub's > "Why Getter and Setter Methods are Evil" article and you should have a > better idea of what OO is supposed to look and feel like. * > > And I just found "Tell, Don't Ask"[2] by the Pragmatic Programmers, > which helps me better understand OO design. > > HTH, > -dave > > * Both links were recently posted in other threads, and I learned a lot > from them. Thanks! :) > > [0] http://www.rubygarden.org/ruby/ruby?WhatIsAnObject > [1] http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html > [2] http://www.pragmaticprogrammer.com/ppllc/papers/1998_05.html Thanks, I will check these out directly. In the mean time I have come up with this as my initial take on things. It does not yet actually move things about but it seems to encompass most of the directory stuff contained in the original script. ------------------------------------------------------------------------------ #++ # mv2dir.rb # version 1.0 - 2006 Feb 16 - James B. Byrne - # # find, move and optionally rename data files that match glob expression # provided. # # ruby mv2dir.rb source_dir glob_exp [target_dir=./] [ext] # or # ruby mv2dir.rb -s source_dir -g glob_exp [-t target_dir] [-e ext] # # TODO: # Options: # -e --ext <str> Append <str> as suffix to each # filename in source. # -g --glob <str> Use <str> as glob pattern to # select source files. # -h --help Display version, help text and exit. # -l --log Log activity to syslog (DEFAULT). # -L --nolog Do not log activity to syslog. # -v --version Display version and exit. # -V --verbose Display activity to STDOUT. # -s --source <str> Use <str> as path to source directory. # -t --target <str> Use <str> as path to target directory. #<<TODO: #-- class Mv2Dir attr_reader :path, :message def initialize(path) @path = path @message = nil if !File.exists?(path) then @message = "#{path} does not exist on this system." elsif !File.directory?(path) then @message = "#{path} exists but is not a directory." else @message = "#{path} is a valid directory." end end def log #TODO add singleton check for open logging process # open one if none exists. Log message to syslog. puts "Log this message #{@message}" end def readable? if !File.readable?(@path) then @message = "#{@path} is not readable." FALSE else @message = "#{@path} is readable." TRUE end end def writable? if !File.writable?(@path) then @message = "#{@path} is not writeable." FALSE else @message = "#{@path} is writeable." TRUE end end def writeable? self.writable? end end # End class Mv2Dir # Run as script after here: if __FILE__ == $0 then # Run as script after here: require 'optparse' options = OptionParser.new puts ARGV.to_s options.on("-h", "-?", "--help", "--about") do |opt| puts "Help text goes here." Process.exit end # define input and output directories with test data files: dir_data_in = "/home/byrnejb/ruby/data/source" dir_data_out = "/home/byrnejb/ruby/data/target" fnm_glob = "QPCCCMR[1-3]" # reference these here lest they go out of scope below. test_in = nil test_out = nil # place these last in test case so that they are available later: ["/","/tmp/","/tmp","no such place/",dir_data_in].each do |din| puts "testing input dir: #{din}" test_in = Mv2Dir.new(din) puts "#{test_in.path.to_s} #{test_in.message.to_s}" puts "#{test_in.readable?.to_s} #{test_in.message.to_s}" puts "#{test_in.writeable?.to_s} #{test_in.message.to_s}" end ["./",dir_data_out].each do |dout| puts "Testing output dir: #{dout}" test_out = Mv2Dir.new(dout) puts "#{test_out.path.to_s} #{test_out.message.to_s}" puts "#{test_out.writeable?.to_s} #{test_out.message.to_s}" end puts test_in.path puts test_out.path end ---------------------------------------------------------------- I have to ask why in Ruby 'elsif' is not 'elseif' and 'writable?' is not 'writeable?' Is there a shortage of 'e's in the the ruby world? On a more serious note, can anyone tell me why the optparse construct given below does not behave as I intend when the script is called thus: #ruby mv2dir.rb --help options.on("-h", "-?", "--help", "--about") do |opt| puts "Help text goes here." Process.exit end Finally, I can use suggestions on how to code the log method. I would like to be able to write things like: test_dir = Mv2Dir.new("/some/path").log or test_dir.writeable?.log but as (test_dir.writeable? = TRUE) this becomes TRUE.log which is, of course, undefined. I am not sure how to do this but what I want is to force a logging event force any Mv2Dir method by appending the .log. Any ideas? -- Posted via http://www.ruby-forum.com/.