From: Joseph Wilk Date: 2008-06-27T01:33:17+09:00 Subject: Indeterministic File order using Dir You cannot guarantee the order of files in the list returned from: ---- Dir['/tmp/*'] ---- The order in which the files are loaded is not deterministic. I had an example were a 32bit machine and a 64bit machine (both ubuntu-hardy) where generating the files in a different order. Some people use Dir as a shortcut to require files. Example: ---- Dir[File.join(File.dirname(__FILE__), 'example/*.rb')].each{ |f| require f } ---- I've come across this on a couple of open-source projects. This is great until you start having dependencies that rely on the order of the files being required. ---- example/x.rb example/y.rb y.rb-> class Y < X x.rb-> class X ---- Its not safe to assume that just because on your machine it loads x.rb first then y.rb that it will use the same order on other machines. I try and ensure that dependencies are required in the files that need them. ---- y.rb-> require 'x' class Y < X x.rb-> class X ---- I'm sure there are lots of other neat idioms that people use to require files. Anyone have any good ideas why a 32bit and 64bit machine would generate a different order on Dir[]? -- Joseph Wilk http://www.joesniff.co.uk -- Posted via http://www.ruby-forum.com/.