# Class extensions in lib not loading

**URL:** <https://www.ruby-forum.com/t/class-extensions-in-lib-not-loading/124605>\
**Category:** Rails\
**Created:** [December 30, 2007, 10:43pm UTC](https://www.ruby-forum.com/t/class-extensions-in-lib-not-loading/124605 "2007-12-30T22:43:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bradley\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7ba0ec/32.png) [@Bradley\_M](https://www.ruby-forum.com/u/Bradley_M)\
**Post date:** [December 30, 2007, 10:43pm UTC](https://www.ruby-forum.com/t/class-extensions-in-lib-not-loading/124605/1 "2007-12-30T22:43:41Z")

</div>

Hi,

I’m using 2.0.2.

If I add a class to ./lib, the class is created and I can access it on  
script/console.

However, if I extend a (core) class using a file in lib, the class  
extension does not occur. The methods I want to add do not appear.  
If I explicitly load the class, the methods get added. But they are  
not done automatically like with other things in lib. Why?

Or, more to the point: What is the correct Rails way to add a method  
to a core Ruby class?

## Thanks, Brad

Bradley M.

---

<div class="post-metadata">

**Author:** ![Bradley\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7ba0ec/32.png) [@Bradley\_M](https://www.ruby-forum.com/u/Bradley_M)\
**Post date:** [January 28, 2008, 11:05pm UTC](https://www.ruby-forum.com/t/class-extensions-in-lib-not-loading/124605/2 "2008-01-28T23:05:28Z")

</div>

I’m seeing the same issue. To get around it I require the file  
directly in config/environment.rb.

For example, I have the file ‘lib/module.rb’ which looks like this:

class Module  
include ModuleExtensions  
end

For some reason this file is not auto loaded. It also seems to happen  
with any other class in the core library I try (Integer, etc.).

So in my environment.rb:

require ‘lib/module’

It would be nice to know if there is a nicer (conventional) way to do  
this.

Regards,  
James

On Dec 30 2007, 3:42 pm, “Bradley M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Bradley\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7ba0ec/32.png) [@Bradley\_M](https://www.ruby-forum.com/u/Bradley_M)\
**Post date:** [January 29, 2008, 5:05pm UTC](https://www.ruby-forum.com/t/class-extensions-in-lib-not-loading/124605/3 "2008-01-29T17:05:44Z")

</div>

For extending core classes you’ve got the main one right there. One  
thing to keep in mind is that files are only read out of /lib at  
startup… that is when you first fire up the console or Rails  
webserver. If you make changes to the file you’ll have to reload! (in  
console) or restart the webserver.
