TruffleRuby Additional Functionality

TruffleRuby is intended to be usable as a standard Ruby implementation that runs programs developed on other implementations, but it also provides additional functionality beyond that of other implementations.

See the Compatibility guide for compatibility with other Ruby implementations.

Detecting If You Run on TruffleRuby

You can use the --version command-line option. TruffleRuby will report for example:

truffleruby ..., like ruby ..., GraalVM CE Native [x86_64-darwin]

In Ruby code, you can look at the standard RUBY_ENGINE constant, which will be 'truffleruby'. In C code TRUFFLERUBY is defined.

It is also possible to use feature-detection instead of looking at RUBY_ENGINE.

TruffleRuby is an integral part of GraalVM, so the version number of TruffleRuby is always the same as the version of GraalVM that contains it. If you are using TruffleRuby outside of GraalVM, such as a standard JVM, the version will be '0.0'. You can find the version number of GraalVM and TruffleRuby using the standard RUBY_ENGINE_VERSION constant.

TruffleRuby Methods and Classes

TruffleRuby provides these non-standard methods and classes that provide additional functionality in the TruffleRuby module:

Atomic References

Concurrent Maps

TruffleRuby::ConcurrentMap is a key-value data structure, like a Hash and using #hash and #eql? to compare keys and identity to compare values. Unlike Hash it is unordered. All methods on TruffleRuby::ConcurrentMap are thread-safe but should have higher concurrency than a fully syncronized implementation. It is intended to be used by gems such as concurrent-ruby - please use via this gem rather than using directly.

FFI

TruffleRuby includes a Ruby-FFI backend. This should be transparent: you can just install the ffi gem as normal, and it will use TruffleRuby’s FFI backend. TruffleRuby also includes a default version of the FFI gem, so require "ffi" always works on TruffleRuby, even if the gem is not installed.

Polyglot Programming

The Polyglot and Java modules provide access to the polyglot programming functionality of GraalVM. They are described in the Polyglot Programming guide.

Unsupported Additional Functionality

You may be able to find some other modules and methods not listed here that look interesting, such as Truffle::POSIX or Truffle::FFI. Additional modules and methods not listed in this document are designed to support the implementation of TruffleRuby and should not be used. They may be modified or made not visible to user programs in the future, and you should not use them.

Extra macros, functions, and variables in TruffleRuby C extension headers beyond those provided by MRI, such as those starting with rb_tr_*, are unsupported and should not be used by any C extension.