Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Detect if your running on windows (See related posts)

It's an unfortunate necessity that you need to write different code for windows sometimes or at the very least load different libraries since there is no fork(), etc. This is how you can tell.

# Returns true if we are running on a MS windows platform, false otherwise.

def Kernel.is_windows?
  processor, platform, *rest = RUBY_PLATFORM.split("-")
  platform == 'mswin32'
end

Comments on this post

delynn posts on Jun 02, 2006 at 20:50
Why not just use a regex like RUBY_PLATFORM =~ /mswin32/ instead of adding the overhead of the split?
scharfie posts on Jul 07, 2006 at 19:40
Really, the test should be something like RUBY_PLATFORM =~ /(win|w)32$/ because you might also have mingw32 and cygwin32

You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts