# Difference between include and require for modules?

**URL:** <https://www.ruby-forum.com/t/difference-between-include-and-require-for-modules/98850>\
**Category:** Ruby\
**Created:** [July 18, 2006, 5:12pm UTC](https://www.ruby-forum.com/t/difference-between-include-and-require-for-modules/98850 "2006-07-18T17:12:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jatinder\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e4f/32.png) [@Jatinder\_S](https://www.ruby-forum.com/u/Jatinder_S)\
**Post date:** [July 18, 2006, 5:12pm UTC](https://www.ruby-forum.com/t/difference-between-include-and-require-for-modules/98850/1 "2006-07-18T17:12:17Z")

</div>

What I understand from require statement is that the argument to it is a  
file, where as include requires module/class name.

But once I do a require for a specific ruby file which has various  
modules  
and classes, doesn’t these classes/modules get included automatically?  
infact they do get automatically as I have tried doing so.

But in various files of ruby library I found that people use include  
“modulename” after a require statement for the file which contains that  
module.

Any reasons?

Thanks,  
Jatinder

---

<div class="post-metadata">

**Author:** ![Jatinder\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a88e4f/32.png) [@Jatinder\_S](https://www.ruby-forum.com/u/Jatinder_S)\
**Post date:** [July 18, 2006, 6:57pm UTC](https://www.ruby-forum.com/t/difference-between-include-and-require-for-modules/98850/2 "2006-07-18T18:57:26Z")

</div>

Jatinder S. wrote:

> Any reasons?
> 
> Thanks,  
> Jatinder

Require is purely used to ‘embed’ files in other files.

Include is used on modules, and adds so-called “MixIn”-functionality.  
It means you “import” the methods of the given Module into the current  
class (or Module?).

So, basically, you have a Module that provides some semi-generic  
functionality, then you have a class that wants to take advantage of  
this functionality.

Example:

module A  
def b  
“bar”  
end  
end

class B  
include A  
end

foo = B.new  
foo.b  
=\> “bar”

I hope this helps!

Ps. this explanation might be horrible, and it might be wrong; I’m not a  
“professional” rubyist. 😉
