如何判断我是从JRuby还是Ruby运行? [英] How can I tell if I'm running from JRuby vs. Ruby?
问题描述
我有一个带有工厂方法的脚本,我想根据某个脚本是从JRuby还是Ruby运行来返回某个类的不同实现.有人对我如何从脚本内部分辨出任何区别有任何想法吗?
I have a script with a factory method that I would like to return a different implementation of some class depending on whether or not the script is running from JRuby or Ruby. Anyone have any ideas on how I could tell the difference from inside my script?
我最初的一些想法是:
-
尝试'include Java'并在失败时恢复到Ruby实现.此方法无效.不管我的开始/救援/结束,Ruby都很聪明,可以出错.
Attempt to 'include Java' and rescue back to the Ruby implementation if it fails. This method doesn't work. Ruby's smart enough to error out regardless of my begin/rescue/end.
使用进程ID愚蠢地做一些事情.我宁愿避免这种情况,因为它总是感觉像是一种骇客.
Do something goofy with process IDs. I'd rather avoid this, since it always feels like a hack.
推荐答案
我相信您可以检查RUBY_PLATFORM常量.
I believe you can check the RUBY_PLATFORM constant.
这篇关于如何判断我是从JRuby还是Ruby运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!