# Require statement clarification

**URL:** <https://www.ruby-forum.com/t/require-statement-clarification/84559>\
**Category:** Ruby\
**Created:** [February 6, 2007, 12:36am UTC](https://www.ruby-forum.com/t/require-statement-clarification/84559 "2007-02-06T00:36:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nevf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/97f17d/32.png) [@nevf](https://www.ruby-forum.com/u/nevf)\
**Post date:** [February 6, 2007, 12:36am UTC](https://www.ruby-forum.com/t/require-statement-clarification/84559/1 "2007-02-06T00:36:48Z")

</div>

For require “filename” if the filename doesn’t include an extension is  
.rb assumed. I’ve been unable to find any documentation on this.

Also the Ruby distribution telnet.rb source file includes:  
require “socket”

however I’m unable to find any socket.rb file anywhere, only a socket.c  
So what does this file refer to?

* * *

Neville F., [http://www.getsoft.com](http://www.getsoft.com) [http://www.surfulater.com](http://www.surfulater.com)

---

<div class="post-metadata">

**Author:** ![nevf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/97f17d/32.png) [@nevf](https://www.ruby-forum.com/u/nevf)\
**Post date:** [February 6, 2007, 12:52am UTC](https://www.ruby-forum.com/t/require-statement-clarification/84559/2 "2007-02-06T00:52:36Z")

</div>

Alle martedÃ¬ 6 febbraio 2007, Neville F. ha scritto:

> Neville F., [http://www.getsoft.com](http://www.getsoft.com) [http://www.surfulater.com](http://www.surfulater.com)  
> You can find the documentation you want with the command ‘ri require’.  
> At any  
> rate, here’s a summary: if the filename has a .rb extension, require  
> loads it  
> as a ruby source file. If it has the extension typical of libraries on  
> that  
> system (for example, .so on unix or .dll on windows), it loads it as a  
> ruby  
> extension. If the extension isn’t specified, it tries adding the  
> extensions  
> to the filename, until it finds an existing file.

Regarding socket, I have a socket.so file located  
in /usr/lib/ruby/1.8/i686-linux (This is on gentoo linux. I think other  
linux  
distributions may have it on different paths. I don’t know about  
windows).  
This means that socket is a C extension. using require ‘socket’ will  
load the  
socket.so file.

I hope this helps

Stefano

---

<div class="post-metadata">

**Author:** ![nevf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/97f17d/32.png) [@nevf](https://www.ruby-forum.com/u/nevf)\
**Post date:** [February 6, 2007, 12:53am UTC](https://www.ruby-forum.com/t/require-statement-clarification/84559/3 "2007-02-06T00:53:36Z")

</div>

Neville F. wrote:

> Neville F., [http://www.getsoft.com](http://www.getsoft.com) [http://www.surfulater.com](http://www.surfulater.com)

If no extension is specified .rb is the default. If Ruby can’t find  
filename.rb it will try to load filename.so. You can specify either .rb  
or .so explicitly.

---

<div class="post-metadata">

**Author:** ![nevf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/97f17d/32.png) [@nevf](https://www.ruby-forum.com/u/nevf)\
**Post date:** [February 6, 2007, 1:00am UTC](https://www.ruby-forum.com/t/require-statement-clarification/84559/4 "2007-02-06T01:00:03Z")

</div>

Thanks for that, especially the ‘ri require’ suggestion.

* * *

Neville F., [http://www.getsoft.com](http://www.getsoft.com) [http://www.surfulater.com](http://www.surfulater.com)
