From: James Byrne Date: 2006-02-22T23:48:33+09:00 Subject: A small refractory problem I have this code: def move(sourcedir,globspec,targetdir,suf=nil) if sourcedir.kindof?(self.class) then sourcedir = sourcedir.path end sourcedir = File.expand_path(sourcedir.to_s) if !self.validpath?(sourcedir) then raise ArgumentError, "Source directory invalid", caller end if targetdir.kindof?(self.class) then targetdir = targetdir.path end targetdir = File.expand path(targetdir.to_s) if !self.validpath?(targetdir) then raise ArgumentError, "Target directory invalid", caller end I would like reduce the duplicate statements into a single block iterated over for source and target. But I lack the ruby syntax knowledge to determine how best to go about this. I would appreciate some examples of how this could be done using an array or a hash and possibly employing symbols. source and target can be an object of the same class or something that can meaningfully converted into a string containing a directory path. I must say that the test/unit approach to programming is, if anything, understated in its effectiveness. I am simply astonished at how easy that the test first approach makes programming and how simple the test/unit framework makes testing first work with ruby. For example, code above was created to deal with a situation that test/unit testing uncovered and which would have been very difficult to track down had the code gotten into production. Regards, Jim -- Posted via http://www.ruby-forum.com/.