To check if a required gem is installed, from within your code, you can use the following (using nokogiri as an example):
begin
found_gem = Gem::Specification.find_by_name('nokogiri')
require 'nokogiri'
....
<the rest of your code>
rescue Gem::LoadError
end
However, this can ...