From: Albert Schlef Date: 2010-02-05T09:25:05+09:00 Subject: Re: Refining the use of file joins or file expand_path Alpha Blue wrote: > The question I have (because I have written used both) is which would > "you" use and why keeping the following in mind... > > Dir[File.join(File.dirname(__FILE__),"..","ui","*.rb")].each {|rb_files| > load rb_files} BTW, there's an alternative to explicit use of File.join() which makes the code more aesthetic: To define String#/, like this: class String def /(o) File.join(self, o.to_s) end end and then you can do: Dir[File.dirname(__FILE__) / ".." / "ui" / "*.rb"] or even: Dir[File.dirname(__FILE__) / ".." / :some / :path / "*.rb"] I once investigated whether File.join() is needed and got the impression that one can just use '/' and things would work. Also, see this: http://rubyforge.org/tracker/index.php?func=detail&aid=13026&group_id=426&atid=1698 Yet I see some Ruby gurus using File.join(). > > Dir[File.join(File.dirname(__FILE__),"..","ui","*.rb")].each {|rb_files| > load rb_files} There's a problem in this approach: if you have a class the inherits from a base class, you need to load the base class first. Dir[] gives you random order(?), which is bad. -- Posted via http://www.ruby-forum.com/.