[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Finding the location of libraries

Claus Spitzer

2/1/2005 5:01:00 PM

Greetings fellow rubyists!
I am looking for a way of checking which location a library I use is
at. Let me demonstrate with an example:

Let's assume that I have a hypotetical programa program, foo.rb . That
program requires a library, as in
require 'bar'

The problem is, I have 4 different versions of bar.rb and one bar.so,
and would like to know which one I am using. How would I go around
figuring this out?

Cheers!

-C.W.S.


4 Answers

Zach Dennis

2/1/2005 5:08:00 PM

0

Claus Spitzer wrote:
> Greetings fellow rubyists!
> I am looking for a way of checking which location a library I use is
> at. Let me demonstrate with an example:
>
> Let's assume that I have a hypotetical programa program, foo.rb . That
> program requires a library, as in
> require 'bar'
>
> The problem is, I have 4 different versions of bar.rb and one bar.so,
> and would like to know which one I am using. How would I go around
> figuring this out?

If you know what you are looking for you can search the $: global
variable which houses the paths that ruby looks in for files.

require "time"
$:.each do |path|
puts "#{path}/time.rb" if File.exist?( "#{path}/time.rb" )
end

here i cheated because I knew I was looking for time. A better solution is:


def require( what )
super
$:.each do |path|
puts "#{path}/#{what}.rb" if File.exist?( "#{path}/time.rb" )
end
end

require "time"

but this will give you output for every required file. Example when I
required "time" I get the following output:

---------- Capture Output ----------
> "c:\ruby\bin\ruby.exe" loadtest.rb -d
c:/ruby/lib/ruby/1.8/rational.rb
c:/ruby/lib/ruby/1.8/date/format.rb
c:/ruby/lib/ruby/1.8/parsedate.rb
c:/ruby/lib/ruby/1.8/time.rb

HTH,


Zach



Robert Klemme

2/1/2005 5:12:00 PM

0


"Claus Spitzer" <docboobenstein@gmail.com> schrieb im Newsbeitrag
news:bb13341905020109007036e0d3@mail.gmail.com...
> Greetings fellow rubyists!
> I am looking for a way of checking which location a library I use is
> at. Let me demonstrate with an example:
>
> Let's assume that I have a hypotetical programa program, foo.rb . That
> program requires a library, as in
> require 'bar'
>
> The problem is, I have 4 different versions of bar.rb and one bar.so,
> and would like to know which one I am using. How would I go around
> figuring this out?

ruby -e '$LOAD_PATH.each {|dir| p Dir[File.join(dir,"bar.*")]}'
ruby -e 'puts $LOAD_PATH.select {|dir| !
Dir[File.join(dir,"bar.*")].empty?}'

Kind regards

robert

Zach Dennis

2/1/2005 5:15:00 PM

0

I had a typo in my last post, the second code fragment should be:


def require( what )
super
$:.each do |path|
puts "#{path}/#{what}.rb" if File.exist?( "#{path}/#{what}.rb" )
end
end

require "time"





HTH,
Zach





Claus Spitzer

2/3/2005 8:35:00 PM

0

Awesome! Thanks to both you and Zach.


On Wed, 2 Feb 2005 02:20:48 +0900, Robert Klemme <bob.news@gmx.net> wrote:
>
> "Claus Spitzer" <docboobenstein@gmail.com> schrieb im Newsbeitrag
> news:bb13341905020109007036e0d3@mail.gmail.com...
> > Greetings fellow rubyists!
> > I am looking for a way of checking which location a library I use is
> > at. Let me demonstrate with an example:
> >
> > Let's assume that I have a hypotetical programa program, foo.rb . That
> > program requires a library, as in
> > require 'bar'
> >
> > The problem is, I have 4 different versions of bar.rb and one bar.so,
> > and would like to know which one I am using. How would I go around
> > figuring this out?
>
> ruby -e '$LOAD_PATH.each {|dir| p Dir[File.join(dir,"bar.*")]}'
> ruby -e 'puts $LOAD_PATH.select {|dir| !
> Dir[File.join(dir,"bar.*")].empty?}'
>
> Kind regards
>
> robert
>
>