diff options
Diffstat (limited to 'vhosts/blog/content/posts/2021-10-02/ruby-detect-running-implementation.xml')
| -rw-r--r-- | vhosts/blog/content/posts/2021-10-02/ruby-detect-running-implementation.xml | 122 |
1 files changed, 0 insertions, 122 deletions
diff --git a/vhosts/blog/content/posts/2021-10-02/ruby-detect-running-implementation.xml b/vhosts/blog/content/posts/2021-10-02/ruby-detect-running-implementation.xml deleted file mode 100644 index 7c0c960d..00000000 --- a/vhosts/blog/content/posts/2021-10-02/ruby-detect-running-implementation.xml +++ /dev/null @@ -1,122 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<article xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0"> - <info> - <title>【Ruby】 自身を実行している処理系の種類を判定する</title> - <abstract> - Ruby には複数の実装があるが、自身を実行している処理系の種類をスクリプト上からどのように判定すればよいだろうか。 - </abstract> - <keywordset> - <keyword>ruby</keyword> - </keywordset> - <revhistory> - <revision> - <date>2021-10-02</date> - <revremark>Qiita から移植</revremark> - </revision> - </revhistory> - </info> - <note> - この記事は Qiita から移植してきたものです。 - 元 URL: <link xl:href="https://qiita.com/nsfisis/items/74d7ffeeebc51b20d791">https://qiita.com/nsfisis/items/74d7ffeeebc51b20d791</link> - </note> - <para> - Ruby - という言語には複数の実装があるが、それらをスクリプト上からどのようにして - programmatically に見分ければよいだろうか。 - </para> - <para> - <literal>Object</literal> クラスに定義されている <literal>RUBY_ENGINE</literal> - という定数がこの用途に使える。 - </para> - <para> - 参考: - <link xl:href="https://docs.ruby-lang.org/ja/latest/method/Object/c/RUBY_ENGINE.html">Object::RUBY_ENGINE</link> - </para> - <para> - 上記ページの例から引用する: - </para> - <programlisting language="shell-session" linenumbering="unnumbered"> - <![CDATA[ - $ ruby-1.9.1 -ve 'p RUBY_ENGINE' - ruby 1.9.1p0 (2009-03-04 revision 22762) [x86_64-linux] - "ruby" - $ jruby -ve 'p RUBY_ENGINE' - jruby 1.2.0 (ruby 1.8.6 patchlevel 287) (2009-03-16 rev 9419) [i386-java] - "jruby" - ]]> - </programlisting> - <para> - それぞれの処理系がどのような値を返すかだが、stack overflow - に良い質問と回答があった。 - </para> - <para> - <link xl:href="https://stackoverflow.com/a/9894232">What values for RUBY_ENGINE - correspond to which Ruby implementations?</link> より引用: - </para> - <blockquote> - <table> - <thead> - <tr> - <td>RUBY_ENGINE</td> - <td>Implementation</td> - </tr> - </thead> - <tbody> - <tr> - <td><undefined></td> - <td>MRI < 1.9</td> - </tr> - <tr> - <td>`ruby'</td> - <td>MRI >= 1.9 or REE</td> - </tr> - <tr> - <td>`jruby'</td> - <td>JRuby</td> - </tr> - <tr> - <td>`macruby'</td> - <td>MacRuby</td> - </tr> - <tr> - <td>`rbx'</td> - <td>Rubinius</td> - </tr> - <tr> - <td>`maglev'</td> - <td>MagLev</td> - </tr> - <tr> - <td>`ironruby'</td> - <td>IronRuby</td> - </tr> - <tr> - <td>`cardinal'</td> - <td>Cardinal</td> - </tr> - </tbody> - </table> - </blockquote> - <para> - なお、この質問・回答は - 2014年になされたものであり、値は変わっている可能性がある。MRI (aka - CRuby) については執筆時現在 (2020/12/8) も <literal>'ruby'</literal> - が返ってくることを確認済み。 - </para> - <para> - この表にない主要な処理系として、https://mruby.org[mruby] は <literal>'mruby'</literal> - を返す。 - </para> - <para> - <link xl:href="https://github.com/mruby/mruby/blob/ed29d74bfd95362eaeb946fcf7e865d80346b62b/include/mruby/version.h#L32-L35">mruby - 該当部分のソース</link> より引用: - </para> - <programlisting language="c" linenumbering="unnumbered"> - <![CDATA[ - /* - * Ruby engine. - */ - #define MRUBY_RUBY_ENGINE "mruby" - ]]> - </programlisting> -</article> |
