# Are files in lib supposed to be loaded automatically?

**URL:** <https://www.ruby-forum.com/t/are-files-in-lib-supposed-to-be-loaded-automatically/161784>\
**Category:** Rails\
**Created:** [March 2, 2009, 1:36pm UTC](https://www.ruby-forum.com/t/are-files-in-lib-supposed-to-be-loaded-automatically/161784 "2009-03-02T13:36:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [March 2, 2009, 1:36pm UTC](https://www.ruby-forum.com/t/are-files-in-lib-supposed-to-be-loaded-automatically/161784/1 "2009-03-02T13:36:07Z")

</div>

Can anyone set me straight on this?

I often put files in lib which add new modules or monkey patch existing  
classes etc. These always need to be explicitly required in my  
environment file. That all works, but one of my colleagues believes  
that everything in lib should be loaded automatically, and that the  
requires should be necessary. This definitely isn’t the case - if i  
remove the require then i dont get the extra functionality.

Is something going wrong for me? Or are lib files not meant to be  
loaded automatically?

thanks  
max

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [March 2, 2009, 2:09pm UTC](https://www.ruby-forum.com/t/are-files-in-lib-supposed-to-be-loaded-automatically/161784/2 "2009-03-02T14:09:30Z")

</div>

On 2 Mar 2009, at 12:36, Max W. wrote:

> Is something going wrong for me? Or are lib files not meant to be  
> loaded automatically?

As far as I know they are not loaded automatically in the sense that  
rails won’t just load them without any intervention from you. They are  
in the sense that if you say MyModule then rails will try and load  
my\_module.rb in lib (among other places). This of course doesn’t work  
if what your file contains is a monkey patch. Perhaps these two  
different meanings of automatically are what are clouding the issue  
(and on top of all that there’s rails 2.2’s ‘load everything on  
startup’ mode which may or may not grab things from /lib - I can’t  
remember)

Fred

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [March 2, 2009, 3:25pm UTC](https://www.ruby-forum.com/t/are-files-in-lib-supposed-to-be-loaded-automatically/161784/3 "2009-03-02T15:25:25Z")

</div>

Frederick C. wrote:

> On 2 Mar 2009, at 12:36, Max W. wrote:
> 
> > Is something going wrong for me? Or are lib files not meant to be  
> > loaded automatically?
> 
> As far as I know they are not loaded automatically in the sense that  
> rails won’t just load them without any intervention from you. They are  
> in the sense that if you say MyModule then rails will try and load  
> my\_module.rb in lib (among other places). This of course doesn’t work  
> if what your file contains is a monkey patch. Perhaps these two  
> different meanings of automatically are what are clouding the issue  
> (and on top of all that there’s rails 2.2’s ‘load everything on  
> startup’ mode which may or may not grab things from /lib - I can’t  
> remember)
> 
> Fred

ah, ok. i think that explains my confusion - i’d seen some stuff work  
without being required. We’re using 2.2.2 though and it’s not grabbing  
everything from lib.

cheers  
max

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [March 2, 2009, 3:54pm UTC](https://www.ruby-forum.com/t/are-files-in-lib-supposed-to-be-loaded-automatically/161784/4 "2009-03-02T15:54:00Z")

</div>

On Mar 2, 2:25 pm, Max W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Frederick C. wrote:

> ah, ok. i think that explains my confusion - i’d seen some stuff work  
> without being required. We’re using 2.2.2 though and it’s not grabbing  
> everything from lib.

I should add that that thing is only turned on in production anyway.

Fred
