#!/usr/bin/ruby -w

class String
  def to_c(base_class = Kernel)
    path = self.gsub(/::/, '.').split(/\./)
    c = base_class::const_get path.shift
    path.each { |i| c = c::const_get i } if path
    c
  end
end

# test suite
if __FILE__ == $0
  class_path, require_string = ARGV

  # if nothign was specified on the command line, then default to
  # Imlib2::Image, and require the imlib2 module
  unless class_path
    class_path = 'Imlib2::Image'
    require_string = 'imlib2'
  end

  # require a module if one was specified on the command line
  require require_string if require_string

  # do our testing
  c_id = nil; eval "c_id = #{class_path}.id"
  c = class_path.to_c
  puts "c.id = #{c.id}",
       "#{class_path}.id = #{c_id}"
end

