# Conditional require? conditional action code?

**URL:** <https://www.ruby-forum.com/t/conditional-require-conditional-action-code/59616>\
**Category:** Rails\
**Created:** [May 4, 2006, 6:05pm UTC](https://www.ruby-forum.com/t/conditional-require-conditional-action-code/59616 "2006-05-04T18:05:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jshow](https://www.ruby-forum.com/u/jshow)\
**Post date:** [May 4, 2006, 6:05pm UTC](https://www.ruby-forum.com/t/conditional-require-conditional-action-code/59616/1 "2006-05-04T18:05:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jshow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/977dab/32.png) [@jshow](https://www.ruby-forum.com/u/jshow)\
**Post date:** [May 5, 2006, 1:01am UTC](https://www.ruby-forum.com/t/conditional-require-conditional-action-code/59616/2 "2006-05-05T01:01:20Z")

</div>

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.
