Skip to content

@ahoward /gemdir.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
~/bin/gemdir
#! /usr/bin/env ruby
# usage: gemdir gemname
#
# eg: cd `gemdir yajl`
#
require 'rubygems'
arg = ARGV.first
unless arg
puts File.join(Gem.dir, "gems")
exit
end
which = arg.dup
which << '*' if which
entries =
Dir[ File.join(Gem.dir, "gems", "#{ which }") ].select{|entry| test ?d, entry}.sort
case entries.size
when 0
abort "no gem #{ which }"
when 1
puts entries.first
else
all_same_name = entries.map{|e| File.basename(e).split('-').first}.uniq.size == 1
if all_same_name
puts entries.last
else
unless STDIN.tty?
warn "ambiguous gemname #{ arg.inspect }"
end
abort(entries.join("\n"))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.