DZone 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
Determine The Operating System In Ruby
This code runs on RUBY_PLATFORM which returns the platform the active copy of ruby was
compiled to run on. I have not found a better method thus far.
module OsFunctions
# universal-darwin9.0 shows up for RUBY_PLATFORM on os X leopard with the bundled ruby.
# Installing ruby in different manners may give a different result, so beware.
# Examine the ruby platform yourself. If you see other values please comment
# in the snippet on dzone and I will add them.
def is_mac?
RUBY_PLATFORM.downcase.include?("darwin")
end
def is_windows?
RUBY_PLATFORM.downcase.include?("mswin")
end
def is_linux?
RUBY_PLATFORM.downcase.include?("linux")
end
end





Comments
Daniel Berger replied on Thu, 2007/07/12 - 5:21pm