#!/usr/bin/env ruby
# -*- ruby -*-

# Copyright 2000, 2001 by Jim Weirich (jweirich@one.net).
# All rights reserved.

# Permission is granted for use, copying, modification, distribution,
# and distribution of modified versions of this work as long as the
# above copyright notice is included.

module Gem

  ####################################################################
  module GemUtils
    
    def class_for (class_name)
      begin
	result = eval(class_name)
      rescue NameError => ex
	# do nothing
      end
      result = find_anonymous_class(class_name) if result.nil?
      fail "No Class Found for |#{class_name}|" if result.nil?
      result
    end
    
    def parent_name_of(class_name)
      if class_name == "" then
	result = ""
      else
	class_obj = class_for(class_name)
	case class_obj
	when Class
	  result = (class_obj == Object) ? "" : class_obj.superclass.to_s
	else
	  result = ""
	end
      end
      result
    end

    def find_anonymous_class(class_name)
      ObjectSpace.each_object(Module) { |mod|
	return mod if mod.to_s == class_name
      }
      nil
    end
    
  end
  
end
