Use as Lib

  • Thread starter Purandhar sairam Mannidi
  • Start date
P

Purandhar sairam Mannidi

How can I use a specific directory as the lib along with ruby library
files????
can Any one reply me with class name or module name?
 
F

Farrel Lifson

How can I use a specific directory as the lib along with ruby library
files????
can Any one reply me with class name or module name?

If you'd like to include a directory into the path ruby searches for
files you can use the -I command line prompt. So to add a directory
called 'lib' you'd write
ruby -Ilib program.rb

Farrel
 
S

sairam MP

Farrel said:
If you'd like to include a directory into the path ruby searches for
files you can use the -I command line prompt. So to add a directory
called 'lib' you'd write
ruby -Ilib program.rb

Farrel

Is there any way that we include in the script itself? like in "use
FindBin qw{$RealBin}; use lib $RealBin;" which will find the present
working directory and will include that in @ISA list.

Sairam
 
S

Stefano Crocco

Alle gioved=EC 15 marzo 2007, Farrel Lifson ha scritto:
If you'd like to include a directory into the path ruby searches for
files you can use the -I command line prompt. So to add a directory
called 'lib' you'd write
ruby -Ilib program.rb

Farrel

Or you can manipulate the $: variable from within ruby. It's an array which=
=20
contains the paths ruby uses when looking for required files. So, if you do

$: << 'my_lib'

you can require a file contained in the directory my_lib with

require 'my_file'

instead of using

require 'my_lib/my_file'

I hope this helps

Stefano
 
M

mully

How can I use a specific directory as the lib along with ruby library
files????
can Any one reply me with class name or module name?

To automatically require all files in a directory?
Some variation of the following might do the trick...

Dir.glob('./directory/*').each do |lib|
require lib
end

Hope that helps.

Mully
 
J

Jan Friedrich

Stefano said:
$: << 'my_lib'
I prefere
$:.unshift 'my_lib'
because this way the path 'my_lib' is prepended to the array and you can
be sure the file in this directory will be found even if another with
the same name exist somewhere else in the search path.

regards
Jan
 
S

sairam MP

Stefano said:
Or you can manipulate the $: variable from within ruby. It's an array
which
contains the paths ruby uses when looking for required files. So, if you
do

$: << 'my_lib'

you can require a file contained in the directory my_lib with

require 'my_file'

instead of using

require 'my_lib/my_file'

I hope this helps

Stefano


Thanks for the Help
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,237
Messages
2,571,190
Members
47,827
Latest member
wyton

Latest Threads

Top