[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Use as Lib

Purandhar sairam Mannidi

3/15/2007 11:38:00 AM

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?

--
Posted via http://www.ruby-....

6 Answers

Farrel Lifson

3/15/2007 11:48:00 AM

0

On 15/03/07, Purandhar sairam Mannidi <sai438@gmail.com> wrote:
> 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?
>
> --
> Posted via http://www.ruby-....
>
>

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

Purandhar sairam Mannidi

3/15/2007 11:54:00 AM

0

Farrel Lifson wrote:
> On 15/03/07, Purandhar sairam Mannidi <sai438@gmail.com> wrote:
>> 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?
>>
>> --
>> Posted via http://www.ruby-....
>>
>>
>
> 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

--
Posted via http://www.ruby-....

Stefano Crocco

3/15/2007 11:55:00 AM

0

Alle giovedì 15 marzo 2007, Farrel Lifson ha scritto:
> On 15/03/07, Purandhar sairam Mannidi <sai438@gmail.com> wrote:
> > 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?
> >
> > --
> > Posted via http://www.ruby-....
>
> 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
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

David Mullet

3/15/2007 12:28:00 PM

0

On Mar 15, 7:37 am, Purandhar sairam Mannidi <sai...@gmail.com> wrote:
> 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?
>
> --
> Posted viahttp://www.ruby-....

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


Guest

3/15/2007 12:38:00 PM

0

Stefano Crocco wrote:
> $: << '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

--
Posted via http://www.ruby-....

Purandhar sairam Mannidi

3/16/2007 4:30:00 AM

0

Stefano Crocco wrote:
> 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

--
Posted via http://www.ruby-....