Skip to content

Instantly share code, notes, and snippets.

@geoloqi
Created July 27, 2011 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geoloqi/1110572 to your computer and use it in GitHub Desktop.
Save geoloqi/1110572 to your computer and use it in GitHub Desktop.
Class for determining platform/version of ruby used. Stolen from bundler.
require 'rbconfig'
module Engine
WINDOWS = RbConfig::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw)!
class << self
def ruby?
!mswin? && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" || RUBY_ENGINE == "rbx")
end
def ruby_18?
ruby? && RUBY_VERSION < "1.9"
end
def ruby_19?
ruby? && RUBY_VERSION >= "1.9"
end
def mri?
!mswin? && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby")
end
def mri_18?
mri? && RUBY_VERSION < "1.9"
end
def mri_19?
mri? && RUBY_VERSION >= "1.9"
end
def rbx?
ruby? && !defined?(RUBY_ENGINE).nil? && RUBY_ENGINE == "rbx"
end
def jruby?
!defined?(RUBY_ENGINE).nil? && RUBY_ENGINE == "jruby"
end
def mswin?
!WINDOWS.nil?
end
def mingw?
!WINDOWS.nil? && Gem::Platform.local.os == "mingw32"
end
def mingw_18?
mingw? && RUBY_VERSION < "1.9"
end
def mingw_19?
mingw? && RUBY_VERSION >= "1.9"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment