How get list of all installed modules/gems in ruby

Hi,

How to get list of all installed modules/gems in ruby otherthan “gem
list”.

-Abhishek

I assume you want the in Ruby code?

Gem::Specification.all() will return a list of Gem::Specification
objects you can then do stuff on (e.g.
Gem::Specification.all().map{|g| [g.name, g.version.to_s] } to return
a list of their names and versions). Full documentation is available
here:

– Matma R.

Thanks.

I want this in ruby code.

above is not working for ruby1.8.7 but working for 1.9.2, is there any
way whichworks for all versions of ruby?

ruby-1.8.7 -e ‘puts Gem::Specification.all().map{|g| [g.name,
g.version.to_s] }’
-e:1: uninitialized constant Gem (NameError)

ruby-1.9.2 -e ‘puts Gem::Specification.all().map{|g| [g.name,
g.version.to_s] }’
NOTE: Specification.all called from -e:1:in `’
minitest
1.6.0
rake
0.8.7
rdoc
2.5.8
ruby-graphviz
1.0.8
ruby-oci8
2.1.2
rubygems-update
1.8.24
sequel
3.37.0

On 10/11/2012 06:10 PM, Abhishek K. wrote:

-e:1: uninitialized constant Gem (NameError)
2.5.8
ruby-graphviz
1.0.8
ruby-oci8
2.1.2
rubygems-update
1.8.24
sequel
3.37.0

Try running it like this;

ruby-1.8.7 -rubygems -e ‘puts Gem::Specification.all().map{|g| [g.name,
g.version.to_s] }’

Sam

In 1.8 you need to require 'rubygems' first, I think.

2012/10/11, Sam D. [email protected]:

g.version.to_s] }’
rdoc

Try running it like this;

ruby-1.8.7 -rubygems -e ‘puts Gem::Specification.all().map{|g| [g.name,
g.version.to_s] }’

Sam


Wysłane z mojego urządzenia przenośnego

– Matma R.

Thanks Sam. It works.

-Abhishek

I’ve always got by with gem list or gem1.9.1 list or whatever is
appropriate for the version of ruby gems I’m interested in.


Matthew K., B.Sc (CompSci) (Hons)
http://matthew.kerwin.net.au/
ABN: 59-013-727-651

“You’ll never find a programming language that frees
you from the burden of clarifying your ideas.” - xkcd

Thanks Matma and matthew.

Is there any way i can get all module list which comes as ruby
installation as well.

-Abhishek