Conditional require? conditional action code?


#1

Greetings all.

I have some controller code that uses win32ole (only available on
windows). This code is now solid, and I’d now like to resume
development on (any) other OS(grin).

But alas, the controller bails because the OS specific library can’t
be found.

Can I conditionally specify action code compilation (and a require
‘win32ole’) based on OS or maybe an environment variable?
(I’m thinking C #IFDEFs)

Or perhaps an empty stub win32ole library for OSX/Linux?

Thanks for your thoughts.

Cheers,
Jodi


#2

You can wrap in if statement around any require. Try this:

if RUBY_PLATFORM =~ /mswin32/ # Matches win32 string in RUBY_PLATFORM
constant
require ‘win32ole’
end

Of course, you’ll need similar code around any place where you actually
use
the Windows specific stuff.