Is there a Ruby method I can call to get the list of installed gems?
I want to parse the output of gem list.
Is there a different way to do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The Gem command is included with Ruby 1.9+ now, and is a standard addition to Ruby pre-1.9.
Here’s an updated way to get a list:
Because
local_gemsrelies ongroup_by, it returns a hash of the gems, where the key is the gem’s name, and the value is an array of the gem specifications. The value is an array of the instances of that gem that is installed, sorted by the version number.That makes it possible to do things like:
And:
The last example is similar to the
gem query --localcommand-line, only you have access to all the information for a particular gem’s specification.