I am trying to dynamically create a class using the eval method. It is working fine except for one small problem. As my code shows I am creating the Browser class inside the BrowserFactory class. When I do this the Browser class has an added namespace of BrowserFactory. Is there anyway to evaluate the Browser class from a string without the BrowserFactory namespace being attached?
class BrowserFactory
def self.create_browser(browser)
super_class = nil
case browser
when 'IE'
require 'watir'
super_class = 'Watir::IE'
when 'celerity'
require 'celerity'
super_class = 'Celerity::Browser'
end
raise StandardError.new("Browser '#{browser}' is not currentlys supported") if super_class.nil?
eval <<EOS
class Browser < #{super_class}
include Singleton
include BrowserModification
end
EOS
return Browser.instance
end
end