I am trying to write a script in Ruby which interactively generate some input data for a program. The idea is use QtRuby when it exists, otherwise console is used. What I tried is to
begin
require "Qt4"
rescue LoadError => load_err
puts "Qt not found, using console"
end
class ConsoleDefine
# console code
end
class QtDefine < Qt::Widget
# GUI code
end
but the interpreter refused my code when Qt4 does not exist. is there a way to deal it similar to C++, like:
#ifdef QT4
class qt4gui
{
// some code
};
#else
class qt4gui
{
// dummy
};
#endif // Qt4
Use require to your advantage:
Create the two files: