Forum: Ruby require statement clarification

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ab5d0d66db7c70b5634be1e28e614383?d=identicon&s=25 Neville Franks (nevf)
on 2007-02-06 00:36
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 Franks,
C40020a47c6b625af6422b5b1302abaf?d=identicon&s=25 Stefano Crocco (crocco)
on 2007-02-06 00:52
(Received via mailing list)
Alle martedì 6 febbraio 2007, Neville Franks ha scritto:
> Neville Franks,
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
system (for example, .so on unix or .dll on windows), it loads it as a
extension. If the extension isn't specified, it tries adding the
to the filename, until it finds an existing file.

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

I hope this helps

3afd3e5e05dc9310c89aa5762cc8dd1d?d=identicon&s=25 Timothy Hunter (Guest)
on 2007-02-06 00:53
(Received via mailing list)
Neville Franks wrote:
> Neville Franks,
If no extension is specified .rb is the default. If Ruby can't find
filename.rb it will try to load You can specify either .rb
or .so explicitly.
Ab5d0d66db7c70b5634be1e28e614383?d=identicon&s=25 Neville Franks (nevf)
on 2007-02-06 01:00
Thanks for that, especially the 'ri require' suggestion.

Neville Franks,
This topic is locked and can not be replied to.