# Require "../foo"

**URL:** <https://www.ruby-forum.com/t/require-foo/49689>\
**Category:** Ruby\
**Created:** [December 7, 2005, 6:45pm UTC](https://www.ruby-forum.com/t/require-foo/49689 "2005-12-07T18:45:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![boris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/74df32/32.png) [@boris](https://www.ruby-forum.com/u/boris)\
**Post date:** [December 7, 2005, 6:45pm UTC](https://www.ruby-forum.com/t/require-foo/49689/1 "2005-12-07T18:45:10Z")

</div>

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”

thanks and greets

Boris

---

<div class="post-metadata">

**Author:** ![boris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/74df32/32.png) [@boris](https://www.ruby-forum.com/u/boris)\
**Post date:** [December 7, 2005, 7:38pm UTC](https://www.ruby-forum.com/t/require-foo/49689/2 "2005-12-07T19:38:16Z")

</div>

Boris G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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

```

---

<div class="post-metadata">

**Author:** ![boris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/74df32/32.png) [@boris](https://www.ruby-forum.com/u/boris)\
**Post date:** [December 8, 2005, 1:39am UTC](https://www.ruby-forum.com/t/require-foo/49689/3 "2005-12-08T01:39:21Z")

</div>

> 

These settings are not meant to be used by the user, but by the  
progammer. I’ve  
stored Constants like names of cgi objects or strings that are used by  
the cgi  
libraries to specify the html version of the generated html code in  
these modules.

Anyway it doesn’t matter what my classes in /lib want to acces. I am  
looking for  
a more elegant way to access classes in /settings from classes the are  
stored in  
/lib. 'require …/settings/globalsettings" ’ ist not accepted by the  
compiler as  
I’ve alread said.

greets Boris

---

<div class="post-metadata">

**Author:** ![boris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/74df32/32.png) [@boris](https://www.ruby-forum.com/u/boris)\
**Post date:** [December 8, 2005, 1:33pm UTC](https://www.ruby-forum.com/t/require-foo/49689/4 "2005-12-08T13:33:00Z")

</div>

Boris G. wrote:

> These settings are not meant to be used by the user, but by the  
> progammer. I’ve stored Constants like names of cgi objects or strings  
> that are used by the cgi libraries to specify the html version of the  
> generated html code in these modules.

The programmer in this case is the user of your lib.

> Anyway it doesn’t matter what my classes in /lib want to acces. I am  
> looking for a more elegant way to access classes in /settings from  
> classes the are stored in /lib. 'require …/settings/globalsettings"  
> ’ ist not accepted by the compiler as I’ve alread said.

But you did actually include the opening quote, did you?

13:23:36 [timezones]: ruby -c -e ‘require “…/foo”’  
Syntax OK  
13:30:53 [timezones]: ruby -c -e ‘require …/foo"’  
-e:1: unterminated string meets end of file  
-e:1: syntax error

My compiler accepts this (i.e. syntax ok). In which of the files do you  
have this line? Is it in the main script or in the lib script? In your  
scripts you can use somehing like

load “…/settings/globalsettings.rb”  
load File.join(File.dirname( **FILE** ), “…”, “settings”,  
“globalsettings.rb”)

Kind regards

```
robert
```
