Forum: Ruby on Rails conditional require? conditional action code?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jodi S. (Guest)
on 2006-05-04 20:05
(Received via mailing list)
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.

Justin B. (Guest)
on 2006-05-05 03:01
(Received via mailing list)
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.
This topic is locked and can not be replied to.