# Cannot require a file that doesnt have a prefix?

**URL:** <https://www.ruby-forum.com/t/cannot-require-a-file-that-doesnt-have-a-prefix/102439>\
**Category:** Ruby\
**Created:** [August 15, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/cannot-require-a-file-that-doesnt-have-a-prefix/102439 "2006-08-15T14:17:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [August 15, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/cannot-require-a-file-that-doesnt-have-a-prefix/102439/1 "2006-08-15T14:17:25Z")

</div>

Huh… why can’t I require a file that has no prefix?

% ls  
redirect

% irb

> require ‘./redirect’  
> LoadError: no such file to load – ./redirect  
> from (irb):1:in `require’  
> from (irb):1  
> from :0

T.

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [August 15, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/cannot-require-a-file-that-doesnt-have-a-prefix/102439/2 "2006-08-15T14:17:25Z")

</div>

Trans wrote:

> Huh… why can’t I require a file that has no prefix?

Er… s/prefix/suffix/

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [August 15, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/cannot-require-a-file-that-doesnt-have-a-prefix/102439/3 "2006-08-15T14:17:26Z")

</div>

Trans wrote:

> Trans wrote:
> 
> > Huh… why can’t I require a file that has no prefix?
> 
> Er… s/prefix/suffix/

Ruby automatically tries different extensions for the files you require,  
so that you do not have to provide an extension when using require.

Check out the documentation.

-Justin

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [August 15, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/cannot-require-a-file-that-doesnt-have-a-prefix/102439/4 "2006-08-15T14:17:40Z")

</div>

Trans wrote:

> Trans wrote:
> 
> > Huh… why can’t I require a file that has no prefix?
> 
> Er… s/prefix/suffix/

This is defined behavior, covered in the file eval.c around #6912  
For the required file to be used as source, it MUST have a “.rb”  
suffix. irb also checks for the extention. If the extention is not  
present, then the extention is ASSUMED, and the require fails  
when that filename+ext is not present. Perhaps a paranoia  
about lots of other languages, etc., but it may save problems  
with other types of files. The extention provides the clues  
necessary to indicate how to handle that file.

Best regards,  
Gerald

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [August 15, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/cannot-require-a-file-that-doesnt-have-a-prefix/102439/5 "2006-08-15T14:17:41Z")

</div>

Hi,

At Sat, 12 Aug 2006 06:55:14 +0900,  
Trans wrote in [ruby-talk:207891]:

> > Huh… why can’t I require a file that has no prefix?

You can load it instead.

---

<div class="post-metadata">

**Author:** ![Trans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dfb087/32.png) [@Trans](https://www.ruby-forum.com/u/Trans)\
**Post date:** [August 15, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/cannot-require-a-file-that-doesnt-have-a-prefix/102439/6 "2006-08-15T14:17:44Z")

</div>

Gerald M. wrote:

> when that filename+ext is not present. Perhaps a paranoia  
> about lots of other languages, etc., but it may save problems  
> with other types of files. The extention provides the clues  
> necessary to indicate how to handle that file.

Okay. Well, I expected it to try the literal path first, then try .rb,  
then try the DLEXT. I’m not sure what problems it saves. I could just  
as well name a python file with .rb. Ruby won’t know the difference  
until it chokes regardless. In my particular usecase I have some  
scripts that can be run as stand alone executables or be required and  
used by another script. So I don’t want them to have the extension. But  
as Nabu said I can use #load instead, so at least I have recourse.

Depending on an extension like this just seems so 80’s, i.e. out-moded.

T.
