# Include vs. require vs. require\_dependency

**URL:** <https://www.ruby-forum.com/t/include-vs-require-vs-require-dependency/121565>\
**Category:** Rails\
**Created:** [November 28, 2007, 11:16pm UTC](https://www.ruby-forum.com/t/include-vs-require-vs-require-dependency/121565 "2007-11-28T23:16:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [November 28, 2007, 11:16pm UTC](https://www.ruby-forum.com/t/include-vs-require-vs-require-dependency/121565/1 "2007-11-28T23:16:42Z")

</div>

i am struggling a bit with all of them … could someone be so nice a  
describe me the exact differences, pros & cons of all of them … thx a  
lot!

---

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [November 29, 2007, 12:52pm UTC](https://www.ruby-forum.com/t/include-vs-require-vs-require-dependency/121565/2 "2007-11-29T12:52:33Z")

</div>

I wrote about include/require in my blog a while back …

[http://francis.blog-city.com/extendingmixin\_ruby\_classes\_with\_modules.htm](http://francis.blog-city.com/extendingmixin_ruby_classes_with_modules.htm)

I’ve never used require\_dependency …

HTH

---

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [November 29, 2007, 1:07pm UTC](https://www.ruby-forum.com/t/include-vs-require-vs-require-dependency/121565/3 "2007-11-29T13:07:21Z")

</div>

On Nov 29, 2007, at 12:52 PM, ghoti wrote:

> I wrote about include/require in my blog a while back …
> 
> [http://francis.blog-city.com/extendingmixin\_ruby\_classes\_with\_modules.htm](http://francis.blog-city.com/extendingmixin_ruby_classes_with_modules.htm)
> 
> I’ve never used require\_dependency …

That’s internal Rails stuff. More or less it means “load this library  
and monitor the constants it defines”.

If your file follows Rails conventions it is picked up automatically  
and class reloading works out of the box.

If the file does not follow them, for example “application.rb” would  
be called “application\_controller.rb” if it did, you can still load it  
and get the benefits of automatic class reloading via  
require\_dependency.

I don’t know whether is meant for public consumption though, since it  
is not documented. Just follow Rails file naming conventions and let  
Dependencies do its job.

– fxn

---

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [November 29, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/include-vs-require-vs-require-dependency/121565/4 "2007-11-29T17:24:33Z")

</div>

thanks for the detailed explanation …  
could you briefly outline the “naming conventions”

---

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [November 29, 2007, 4:27pm UTC](https://www.ruby-forum.com/t/include-vs-require-vs-require-dependency/121565/5 "2007-11-29T16:27:15Z")

</div>

On Nov 29, 2007, at 5:52 AM, ghoti wrote:

> I wrote about include/require in my blog a while back …
> 
> [http://francis.blog-city.com/extendingmixin\_ruby\_classes\_with\_modules.htm](http://francis.blog-city.com/extendingmixin_ruby_classes_with_modules.htm)

Nice simple explanation. Thanks,

By the way, and totally off-topic, to anybody wondering about the name  
“ghoti,” if I recall correctly, it’s an alternate “spelling” of the  
word fish, using the gh from laugh, the o from women, an the ti from  
nation.  
It was constructed by somebody (I don’t remember who) a long long time  
ago complaining about spelling in English. I hadn’t thought of it in  
many years until I saw it here. 🙂

---

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [November 29, 2007, 7:16pm UTC](https://www.ruby-forum.com/t/include-vs-require-vs-require-dependency/121565/6 "2007-11-29T19:16:13Z")

</div>

i see… but this applies only to the contents within the “app”  
directory doesnt it?

---

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [November 29, 2007, 7:23pm UTC](https://www.ruby-forum.com/t/include-vs-require-vs-require-dependency/121565/7 "2007-11-29T19:23:42Z")

</div>

On Nov 29, 2007, at 7:16 PM, Michal G. wrote:

> i see… but this applies only to the contents within the “app”  
> directory doesnt it?

Not really. It applies to the contents listed in  
Dependencies.load\_path, which in addition to app subdirs include lib  
and a few others. Check it out in the console.

That list may be further customised via config.load\_paths in  
environment.rb.

– fxn

---

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [November 29, 2007, 5:57pm UTC](https://www.ruby-forum.com/t/include-vs-require-vs-require-dependency/121565/8 "2007-11-29T17:57:24Z")

</div>

On Nov 29, 2007, at 5:24 PM, Michal G. wrote:

> thanks for the detailed explanation …  
> could you briefly outline the “naming conventions”

Sure, take the fully-qualified name of the class you want Rails to  
autoload and run this:

```
$ script/console
Loading development environment.
>> "FooBar::Woo".underscore + '.rb'
=> "foo_bar/woo.rb"

```

That says that if the class FooBar::Woo is defined in a file named  
“foo\_bar/woo.rb” living inmediately below some standard application  
directory like app/controllers Rails will find the file and load it  
for you automatically.

For example, if you define the User class in the file user.rb under  
app/models you don’t need to require ‘user’. Note you would in regular  
Ruby.

– fxn

---

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [November 29, 2007, 7:25pm UTC](https://www.ruby-forum.com/t/include-vs-require-vs-require-dependency/121565/9 "2007-11-29T19:25:43Z")

</div>

thanks… great help!! will try to use that knowledge…
