From: Ron Jeffries Date: 2002-01-13T14:07:25+09:00 Subject: Re: FileHandle (was: Re: Dir.entries have no home) On Sun, 13 Jan 2002 02:56:32 GMT, Massimiliano Mirra wrote: > def location=(new) > @info[:location][:new] = new > @info[:path][:new] = File.join(@info[:location][:new], @info[:name][:new]) > end > > def name=(new) > @info[:name][:new] = new > @info[:path][:new] = File.join(@info[:location][:new], @info[:name][:new]) > end > > def path=(new) > @info[:path][:new] = new > @info[:name][:new] = File.basename(@info[:path][:new]) > @info[:location][:new] = File.dirname(@info[:path][:new]) > end A couple more things, then I really am going to bed. Seems like that last method could be written as > def path=(new) > @info[:path][:new] = new > @info[:name][:new] = File.basename(new) > @info[:location][:new] = File.dirname(new)) > end unless I'm missing something. Am I? Also, it seems that these methods are trying to maintain a consistency relationship between name, path, and location. Why not instead just let path be virtual and maintain the other two, something like this: > def location=(new) > @info[:location][:new] = new > end > > def name=(new) > @info[:name][:new] = new > end > > def path=(new) > @info[:name][:new] = File.basename(new) > @info[:location][:new] = File.dirname(new) > end with also > def path > File.join(@info[:location][:new], @info[:name][:new]) > end Wouldn't something like that be simpler and less prone to error? Then, finally, instead of the hash, I might prefer to set up an object of class, say, FileInfo with instance variables and accessors location, path, name and so on, and to have two instances of FileInfo in FileHandle, @newInfo and @oldInfo, so we could write def name=(new) @newInfo.name=new end and the like. Maybe there's some complex manipulation of the new and old that I don't understand yet that would get in the way of doing this ... Or maybe I just don't get it. Hmm? Regards, Ronald E Jeffries http://www.XProgramming.com http://www.objectmentor.com I'm giving the best advice I have. You get to decide whether it's true for you.