Twitter Updates

Sunday 22 March 2009

Ruby finding OS

To find the Operating System that you ruby script/program is running on you can do:
puts RUBY_PLATFORM

To return one of Windows, Mac, Linux you could do:
if (RUBY_PLATFORM.include? ("darwin"))
os = "Mac"
elsif (RUBY_PLATFORM.include? ("nix"))
os = "Linux"
elsif (RUBY_PLATFORM.include? ("Win"))
os = "Windows"
else
os = ""
end

there is also
puts ENV['OS']
but this only works on windows and is empty for Linux and Mac OS X

No comments: