0

Is there a way to ask Ruby what operating system it's running on?

I am using the clipboard gem in conjunction with Selenium and I need the script to run on all systems.

Since the "copy" keyboard shortcut is different on OSX vs. Windows, I would like to be able to tell which operating system my script is being run on.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Zach
  • 885
  • 2
  • 8
  • 27

1 Answers1

2

You can use the RUBY_PLATFORM constant to inquire:

>> RUBY_PLATFORM
=> "i686-linux"

For this purpose we have used code similar to https://github.com/kotp/rlcw/blob/master/lib/platform.rb:

module Platform

  def check_operating_system
    # The Mac check has to be proceed before the Win check!
    # Perhaps checking for /mswin/ will reduce this requirement.
    case RUBY_PLATFORM
    when /ix/i, /ux/i, /gnu/i, /sysv/i, /solaris/i, /sunos/i, /bsd/i
      require 'gtk2'
      Gtk.init
      @clip = Gtk::Clipboard.get(Gdk::Selection::CLIPBOARD)
      :unix
    when /darwin/i
      :mac_os_x
    when /mswin/i, /ming/i
      require 'vr/clipboard'
      @clip = Clipboard.new(2048)
      :windows
    else
      :other
    end
  end

end
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
vgoff
  • 10,980
  • 3
  • 38
  • 56