# Where to place class files?

**URL:** <https://www.ruby-forum.com/t/where-to-place-class-files/107366>\
**Category:** Ruby\
**Created:** [June 20, 2007, 10:44pm UTC](https://www.ruby-forum.com/t/where-to-place-class-files/107366 "2007-06-20T22:44:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shadowcipher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@shadowcipher](https://www.ruby-forum.com/u/shadowcipher)\
**Post date:** [June 20, 2007, 10:44pm UTC](https://www.ruby-forum.com/t/where-to-place-class-files/107366/1 "2007-06-20T22:44:43Z")

</div>

I wrote my own class definition and placed it inside a file called  
mynewclass.rb. I then placed this file inside  
/usr/local/lib/ruby/1.8/mynewclass/.

The mynewclass.rb file has

require ‘rubygems’  
require ‘uuidtools’  
require ‘xml\_struct’

inside of it.

When I create a new ruby script and use

require ‘mynewclass/mynewclass’

I get a load error from custom\_require.rb saying there is no such file  
to  
load for uuidtools and xml\_struct, however if I launch irb and do a  
require  
‘mynewclass/mynewclass’ I can use the class just fine with no load  
errors.

Is there a different method I should use to go about this the correct,  
and  
hopefully functional way?

- Nathan

---

<div class="post-metadata">

**Author:** ![shadowcipher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@shadowcipher](https://www.ruby-forum.com/u/shadowcipher)\
**Post date:** [June 21, 2007, 11:10am UTC](https://www.ruby-forum.com/t/where-to-place-class-files/107366/2 "2007-06-21T11:10:44Z")

</div>

Dear Nathan,

in what directory did you save the new script ?

Assuming that it is saved as /home/nathan/new\_script.rb,

if you write

require “mynewclass/mynewclass”

into it, the error message you get is due to the fact that  
you don’t have a /home/nathan/mynewclass subdirectory  
with a mynewclass.rb file in it.  
So you could give the full pathname, or save the mynewclass.rb  
script in the same directory as new\_script.rb .

Alternatively, you could set additional environment variables  
for ruby:

[http://www.rubycentral.com/book/rubyworld.html](http://www.rubycentral.com/book/rubyworld.html)

It sounds to me that you get this error because you expect  
Ruby to behave like Java … right?

If so, could you help me on a Ruby/Java problem for which  
I got no response so far ?

[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/256316](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/256316)

Thank you very much!

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![shadowcipher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/45deac/32.png) [@shadowcipher](https://www.ruby-forum.com/u/shadowcipher)\
**Post date:** [June 21, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/where-to-place-class-files/107366/3 "2007-06-21T16:29:31Z")

</div>

The new\_script.rb is saved in my home directory, however the  
mynewclass.rbfile is saved in the site\_ruby directory that is  
recommended for placing end  
user created modules and extensions to ruby. I dont’ have a problem  
with  
new\_script.rb being able to load mynewclass.rb. The problem is that  
inside  
of mynewclass.rb it also requires a few ruby gems, and those ruby gems  
are  
what I am getting load errors for. The gems and mynewclass.rb are both  
in  
directories included in the default ruby load path, which is why I am  
quite  
confused at the errors generated.

Sorry, I wish I could help, but I have never coded in Java! I have  
some  
limited knowledge of web apps implemented in Java and I believe you have  
to  
download the required libraries, place them in a lib directory, and then  
some how you should be able to create a configuration file that points  
to  
the libraries. Have only seen implementations for servlet and jsp code  
though, so I’m not sure how that all works with a normal Java  
application.
