[BUMP] 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.


I think you will want to hide the OS dependent stuff in a class. The
can then detect the operating system and respond with the desired
functionality if available, or fail gracefully if not. I think you can
detect the operating system from the Ruby config file. This is from
“Programming Ruby”:

require “rbconfig.rb”
include Config
CONFIG[“host”] â?? “i686-pc-linux”
CONFIG[“LDFLAGS”] â?? “-rdynamic”

Try playing around with CONFIG and see if there are values in there that
will tell you what you need to know.


Great info Eden - thanx. I’ll dig in.

Although my implementation will vary the core code looks like,

require ‘rbconfig’
include Config

require ‘win32ole’ if CONFIG[“build_os”] =~ /mswin/

Thanx Eden - Happy to be back testing on osx!