require 
Author Message
 require

   Guys,

   When we use

require 'some_code'.

where (i.e., in which directories) does require looks for 'some_code'?

   Thanks,
   Maurcio



Tue, 31 May 2005 01:57:28 GMT  
 require

Quote:
>>>>> "M" == =?ISO-8859-1?Q?Maur=EDcio?=  <ISO-8859-1> writes:

M> require 'some_code'.

M> where (i.e., in which directories) does require looks for 'some_code'?

 $LOAD_PATH

pigeon% ruby -e 'p $LOAD_PATH'
["/usr/local/lib/ruby/site_ruby/1.6",
"/usr/local/lib/ruby/site_ruby/1.6/i686-linux",
"/usr/local/lib/ruby/site_ruby", "/usr/local/lib/ruby/1.6",
"/usr/local/lib/ruby/1.6/i686-linux", "."]
pigeon%

Guy Decoux



Tue, 31 May 2005 02:00:47 GMT  
 require
Hi --

Quote:

>    Guys,

>    When we use

> require 'some_code'.

> where (i.e., in which directories) does require looks for 'some_code'?

Short answer: those listed in the global variable $:

Longer answer:

candle:~$ ri require
-------------------------------------------------------- Kernel::require
     require( aString ) -> true or false
------------------------------------------------------------------------
     Ruby tries to load the library named aString, returning true if
     successful. If the filename does not resolve to an absolute path,
     it will be searched for in the directories listed in $:. If the
     file has the extension ``.rb'', it is loaded as a source file; if
     the extension is ``.so'', ``.o'', or ``.dll'',[Or whatever the
     default shared library extension is on the current platform.] Ruby
     loads the shared library as a Ruby extension. Otherwise, Ruby tries
     adding ``.rb'', ``.so'', and so on to the name. The name of the
     loaded feature is added to the array in $". A feature will not be
     loaded if it already appears in $". require returns true if the
     feature was successfully loaded.
        require "my-library.rb"
        require "db-driver"

David

--
David Alan Black


Web:  http://pirate.shu.edu/~blackdav



Tue, 31 May 2005 02:04:50 GMT  
 require
Hi --

Quote:

> >>>>> "M" == =?ISO-8859-1?Q?Maur=EDcio?=  <ISO-8859-1> writes:

> M> require 'some_code'.

> M> where (i.e., in which directories) does require looks for 'some_code'?

>  $LOAD_PATH

Whoops, I gave the Perlish version :-)

David

--
David Alan Black


Web:  http://pirate.shu.edu/~blackdav



Tue, 31 May 2005 02:05:24 GMT  
 require
   Interesting... The good-style way of changing it is just
$LOAD_PATH.push 'directory' ?
Quote:

> "M" == =?ISO-8859-1?Q?Maur=EDcio?=  <ISO-8859-1> writes:

> M> require 'some_code'.

> M> where (i.e., in which directories) does require looks for 'some_code'?

>  $LOAD_PATH

> (...)



Tue, 31 May 2005 02:12:03 GMT  
 require
Hi --

Quote:

>    Interesting... The good-style way of changing it is just
> $LOAD_PATH.push 'directory' ?

Depending on the situation, you might want to shift instead of
pushing, so that the directories you're adding get searched first.

David

--
David Alan Black


Web:  http://pirate.shu.edu/~blackdav



Tue, 31 May 2005 02:18:01 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. require, require-library in PLT-scheme

2. Information on Smalltalk Sockets ( if exist ) required

3. Structured APL requires abandoning dynamic scope?

4. A Language Primer required for A Programming Language

5. URGENT-Visual Age Smalltalk-Required

6. Help required with KEYFAST product

7. 'StdCLib required'

8. Layout of catalog required

9. Is HLASM conversion required for Y2K?

10. Target2000 Resellers Required

11. 10 SMALLTALK VISUALWORKS DEVELOPERS REQUIRED - Contract 18 months

 

 
Powered by phpBB® Forum Software