From: Adam Shelly Date: 2008-08-14T02:28:55+09:00 Subject: Re: what do you think of this code? On 8/13/08, Ben Aurel wrote: > thanks for the input. Here are my changes and my reasoning about it: > > - like the unix 'ls' command the default parameter is '.' > > - I demand 'path' as a initialize argument but I wont set a default > value because creating a new instance with new() is wrong and should > raise an error. This doesn't make sense to me. Why shouldn't you be able to create a new instance without an argument and have it default to the current directory? System 'ls' defaults to the current directory. I think I shoud be able to type "ls.rb" without arguments and get the current directory list, not a "No Argument" warning. To make it work like that, I would use a default argument, > 4 def initialize(path = '.') > 5 @path = path.empty? ? '.' : path > 8 if File.exists?(@path) ... and remove the 'elsif dir' clause before the begin block at the end of your script. Also, a standard idiom for files that can be either run from the command line or required is to put this test around the command line handling part: if __FILE__ == $0 end That condition will only be true if this file is being executed directly, not when it is 'require'd. -Adam