- 论坛徽章:
- 0
|
Ruby怎样获取操作系统的Name
在看Selenium源代码的时候, 发现了获取操作系统的更好方法
Ruby代码- 1.def os
- 2. @os ||= (
- 3. host_os = RbConfig::CONFIG['host_os']
- 4. case host_os
- 5. when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
- 6. :windows
- 7. when /darwin|mac os/
- 8. :macosx
- 9. when /linux/
- 10. :linux
- 11. when /solaris|bsd/
- 12. :unix
- 13. else
- 14. raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
- 15. end
- 16. )
- 17. end
- def os
- @os ||= (
- host_os = RbConfig::CONFIG['host_os']
- case host_os
- when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
- :windows
- when /darwin|mac os/
- :macosx
- when /linux/
- :linux
- when /solaris|bsd/
- :unix
- else
- raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
- end
- )
- end
复制代码 之前用的方法是假定是windows, 如果不是的话根据异常处理来判断是否是Mac, 很麻烦 |
|