[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

How to test if a module/gem is installed

snacktime

10/21/2006 9:23:00 PM

Is there a way to test if a particular module/extension/gem is
installed on the system ruby is running on?

Chris

5 Answers

Trans

10/21/2006 9:55:00 PM

0

I wrote this extension for that. Not sure how robust it is though.

module Gem

def self.active?(gemname)
@loaded_specs ||= Hash.new
@loaded_specs.key? gemname
end

end

T.


Paul Lynch

10/21/2006 11:18:00 PM

0

On 21 Oct 2006, at 22:23, snacktime wrote:

> Is there a way to test if a particular module/extension/gem is
> installed on the system ruby is running on?

If you know the library name for a require statement, use require and
trap the LoadError? Returns true if the require succeeds.

Paul

J2M

10/22/2006 1:56:00 PM

0

you can find all the installed gems with a version of this;

def find_my_gem(name)
spec_dir = File.join(Gem.dir, "specifications")
gems = Gem::SourceIndex.from_installed_gems(spec_dir)
gems.each {|path, gem| return true if name == gem.name}
return false
end

this is a bit of a hack together, but gives you the basic idea.


J2M

10/22/2006 1:59:00 PM

0

probably need brackets around trun in the return(true)


snacktime

10/22/2006 8:19:00 PM

0

Thanks for all the tips guys, was a great help.