From: Robert Klemme Date: 2005-12-08T03:37:35+09:00 Subject: Re: require "../foo" Boris Glawe wrote: > Hi, > > I have my code splitted up in several directories: > > ... > lib/foo.rb > lib/bar.rb > setttings/globalsettngs.rb > setttings/othersettings.rb > ... > > If for example foo.rb want to use classes, modules or methods from > "settings/globalesettings.rb" the ruby compiler refuses this in > foo.rb: > require "../settings/globalsettings" > > I always use this as a workaround: > $: << ".." > require "settings/globalsettings" > > where $: is the variable storing the path where to search for files. > > Is there a more elegant way to access files in "../settings" I assume, files in settings contain info that is specific to your code in foo and bar which the user has to create / provide. In that case I'd also rely on the user to set the require path so that his settings can be found. I'd also probably not necessarily use "require" to load those settings. This for example has the disadvantage that you cannot easily reload settings. I'd probably rather read something like "~/.foo.rb" i.e. settings stored in a default location (which might be overridden with a command line switch). Kind regards robert