tags:

views:

40

answers:

2

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.

+1  A: 

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.

shingara
A: 

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.

Beanish
or just use `grep require rubyfile.rb` ;)
Mladen Jablanović