Skip to content

Instantly share code, notes, and snippets.

@mutle
Created March 6, 2009 17:34
Show Gist options
  • Save mutle/74986 to your computer and use it in GitHub Desktop.
Save mutle/74986 to your computer and use it in GitHub Desktop.
def has_gem?(name, version=nil)
if !$GEM_LIST
gems = {}
`gem list --local`.each_line do |line|
gems[$1.to_sym] = $2.split(/, /) if line =~ /^(.*) \(([^\)]*)\)$/
end
$GEM_LIST = gems
end
if $GEM_LIST[name.to_sym]
return version ? $GEM_LIST[name.to_sym].include?(version) : true
end
false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment