Conditional require? conditional action code?

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.


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

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

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