Chris J
Chris J

Reputation: 9252

Is there a quick way to get a list of gems that a ruby script needs?

I've been hacking around with Ruby a little and I have been wondering if there is a utility or tool that you can use to determine all the gems that a ruby script requires. Basically, I have been finding it kind of annoying having to work with a ruby script that I didn't write, I don't know all the gem dependencies for, and I don't know if said gems are all installed.

Upvotes: 0

Views: 135

Answers (2)

Beanish
Beanish

Reputation: 1662

Personally I typically just try to run something and if it breaks install the required gem, or take a quick look at the first couple of lines and see if you can find the requires. I don't know of a pre-existing tool, but I'll be glad if someone tells us of one.

Ruby is a scripting language so keep exploring and maybe make your own. Will it be perfect? Maybe not, but you'll learn some stuff on the way.

f = File.open('rubyfile.rb')

f.each do |line|
  if line.include?('require') then
    puts line
  end
end

There is a starting point. That solution misses a bunch of stuff, like nested dependencies, what if a required file also has some requires, what if you want to check includes? Make it check the whole file structure of a project and check any .rbs? Maybe make it use a regex instead of a string to avoid other instances of the word require throughout the script etc.

Upvotes: 0

shingara
shingara

Reputation: 46914

The using of bundler help to know all gem is needed. But You can't to know which is required. Because you can use gem or other system to require your librarie.

Upvotes: 1

Related Questions