From: Joel VanderWerf Date: 2003-01-24T03:59:48+09:00 Subject: Re: emulating C preprocessor's #if Yuri Leikind wrote: > Perhaps I might have misunderstood the main point of your letter, but I > think Ruby is dynamic enough to do what you want without any other > changes in the core language: > > module M > > def M.print_platform > print "Platform is..." + M.platform_dependent_code() + "\n" > end > > case RUBY_PLATFORM > > when /solaris/i then > def M.platform_dependent_code > "Solaris" > end > when /linux/i then > def M.platform_dependent_code > "Solaris" > end > when /win/i then > def M.platform_dependent_code > "Solaris" > end > else > def M.platform_dependent_code > "unknown" > end > end > end > > M.print_platform My example was too simple :) I'm thinking of a case where platform-dependent code is mixed with independent code and hard to factor out without making a lot of extra method calls. Also, if you have more variables than just platform, you get combinatorial explosion if you have to write a separate method for each possibility. My suggestion is a last resort...