Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Determine The Operating System In Ruby

DZone's Guide to

Determine The Operating System In Ruby

·
Free Resource
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
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}