Tuesday, 15 September 2015

How to make Ruby partially parse the source code? -



How to make Ruby partially parse the source code? -

i trying write script in ruby interactively generate input info program. thought utilize qtruby when exists, otherwise console used. tried 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 interpreter refused code when qt4 not exist. there way deal similar c++, like:

#ifdef qt4 class qt4gui { // code }; #else class qt4gui { // dummy }; #endif // qt4

use require advantage:

begin require "qt4" require "my_lib/qt4" rescue loaderror => load_err puts "qt not found, using console" require "my_lib/console" end

create 2 files:

# my_lib/console.rb class consoledefine # console code end # my_lib/qt4.rb class qtdefine < qt::widget # gui code end

ruby

No comments:

Post a Comment