From: Vladimir Sizikov Date: 2008-07-30T15:31:34+09:00 Subject: [ruby-core:18026] Re: RUBY_ENGINE? Hi, On Wed, Jul 30, 2008 at 7:46 AM, Luis Lavena wrote: > On Wed, Jul 30, 2008 at 6:19 AM, Tanaka Akira wrote: >> What's problem of rescue LoadError? >> >> begin >> gem 'activerecord-jdbc-adapter' >> require 'jdbc_adapter' >> adapter = 'jdbcmysql' >> rescue LoadError >> adapter = 'mysql' >> end >> >> Why do you like RUBY_ENGINE over LoadError? >> > > Because: > > 1) user can force the installation of the gem: > > gem install activerecord-jdbc-adapter --platform=java even java is not > one of the platforms the implemenetation supports. > > The require will work, but it will raise later then other kind of > errors that your rescue is not covering. Also, what if the application to support more implementations? How about 4? MRI, JRuby, Rubinius, IronRuby? You'll have very messy, nested (4-level deep) requires with no guarantees that they would work as expected. (Not to mention that even on JRuby that gem/require won't work if user forgot to install the gem first). In short, unsuccessfull require doesn't mean we're not on JRuby, and successful require doesn't mean that either. Granted, users might figure out the current Ruby implementation one way or another, but they will be not precise ways. Thanks, --Vladimir