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
classkeyword in Ruby is just an expression (this differs from languages like Java/C# where it is a declaration). As such they can be nested in other statements/expressions:if defined? Qt; class QtDefine < Qt::Widget; ..; end; end.. now, is this "good"? Well, that's what the real answers are for :D