Module: Kernel

Defined in:
lib/vendor/twitter/lib/twitter/ext/stdlib.rb

Overview

Extension to Kernel to add #gem_present? without any exceptions raised

Instance Method Summary collapse

Instance Method Details

#gem_present?(gem_name, version = nil) ⇒ Boolean

Returns whether or not a gem exists without raising a Gem::LoadError exception

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
# File 'lib/vendor/twitter/lib/twitter/ext/stdlib.rb', line 42

def gem_present?(gem_name, version = nil)
  present = false
  begin
    present = !!(version ? gem(gem_name, version) : gem(gem_name))
  rescue Gem::LoadError => le
    present = false
    warn("Gem load error: Couldn't load #{gem_name} #{version ? "with version requirement #{version}: #{le.to_s}": ""}")
  end
  present
end