#
# find_all_gem_commands(gem_command='gem')
#
# Examples:
#
# MacOS 10.5.2
#
#   find_all_gem_commands                                                                       
#   => [{"ruby"=>"/usr/bin/gem"}, {"jruby"=>"/Users/stephen/dev/jruby_trunk/jruby/bin/gem"}]    
#   find_all_gem_commands('rails') 
#                                                             
#   => [{"ruby"=>"/usr/bin/rails"}, {"jruby"=>"/Users/stephen/dev/jruby_trunk/jruby/bin/rails"}]
#
# Windows:
#
#   find_all_gem_commands
#   => [{"ruby.exe"=>"D:\\re\\ruby\\bin/gem"}, {"ruby.exe"=>"D:\\cygwin\\bin/gem"}, {"jruby"=>"D:\\work\\jruby-dev\\jruby\\bin/gem"}]
#
def find_all_gem_commands(gem_command='gem')
  environment_path = ENV['PATH'] || ENV['Path']
  gem_command_locations = environment_path.split(File::PATH_SEPARATOR).find_all {|path| File.exists?(path + File::SEPARATOR + gem_command)}.uniq
  gem_command_locations =  gem_command_locations.collect {|path| path + File::SEPARATOR + gem_command}
  gem_commands = []
  gem_command_locations.each do |location|
    gem_commands << {File.open(location) {|f| f.gets.strip}[/[\w.]*$/] => location}
  end
  gem_commands
end