From: Joel VanderWerf Date: 2003-01-24T03:36:04+09:00 Subject: emulating C preprocessor's #if Usually, when writing ruby code, I don't worry about conditional compilation, and just use a run-time test. But for some critical code, I prefer to factor the conditional out to compile time. Unfortunately, this can require either a lot of duplication of source code, or awkwardly factoring out sub-methods which are conditionally compiled. Sometimes, the following approach is more convenient: module M solaris = (RUBY_PLATFORM =~ /solaris/i) linux = (RUBY_PLATFORM =~ /linux/i) windows = (RUBY_PLATFORM =~ /win/i) module_eval %{ def self.print_platform print "Platform is... " #{ if solaris then %{ puts "solaris" } elsif linux then %{ puts "linux" } elsif windows then %{ puts "windows" } else %{ puts "unknown" } end } end } end M.print_platform