在 Ruby 中检测操作系统 [英] Detecting Operating Systems in Ruby

查看:31
本文介绍了在 Ruby 中检测操作系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 ruby​​ 中检测操作系统?我正在开发一个需要检测 Mac 与 Windows 的 SketchUp 工具.

Is there a way to detect the operating system in ruby? I am working on developing a sketchup tool that will need to detect Mac vs. Windows.

推荐答案

你可以使用 os gem:

You can use the os gem:

gem install os

然后

require 'os'
OS.linux?   #=> true or false
OS.windows? #=> true or false
OS.java?    #=> true or false
OS.bsd?     #=> true or false
OS.mac?     #=> true or false
# and so on.

参见:https://github.com/rdp/os

这篇关于在 Ruby 中检测操作系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆