Note: This documentation refers to ROOT5. ROOT6 Ruby bindings are planned. Ruby ROOT is a Ruby extension module that allows the user to interact with any ROOT class from the Ruby scripting language. The Ruby module resolves ROOT Classes and Methods at run-time using the CINT API, so there is no need for wrapping specific Classes to be used in Ruby. The Ruby module, also, contains a TRuby class to execute Ruby statements via CINT and export C++ Objects to Ruby objects, interactively. To learn more about the Ruby-Root interface see the Diploma Thesis of Elias Athanasopoulos (email@example.com).
Building and Installing the Ruby Module
The Ruby extension module is not built by default when building ROOT from sources. The user should follow the standard installation instructions and enable the build of the Ruby module. Ruby version >= 1.8 is required.
./configure <arch> --enable-ruby --enable-explicitlink \ [--with-ruby-incdir=<dir>] [--with-ruby-libdir=<dir>] gmake
If you do not specify the inc and lib directories configure will use Ruby to grab the directories where Ruby's headers and library are located. A library called libRuby.so [libRuby.dll] will be created in the $ROOTSYS/lib [$ROOTSYS/bin].
Running ROOT scripts from Ruby
The user should make sure that the ruby command is the one of the installation that has been used to build the Ruby extension module. If the RUBYLIB enviroment variable is set correctly, the user can execute a Ruby script with ROOT functionality in the following way:
ruby -rlibRuby foo.rb
Another way is to start the Ruby script with the Ruby require command:
An example is as follows:
require 'libRuby' gROOT.Reset c1 = TCanvas.new('c1', 'Example with Formula', 200, 10, 700, 500) # # Create a one dimensional function and draw it # fun1 = TF1.new('fun1', 'abs(sin(x)/x)', 0, 10) c1.SetGridx c1.SetGridy fun1.Draw c1.Update
The user can find a number of examples in the $ROOTSYS/tutorials. To run them you need to execute the command:
cd $ROOTSYS/tutorials ruby demo.rb
Invoking the Ruby module from ROOT/CINT interpreter
A ROOT user can run any Ruby command and eventually to run IRB, the Interactive Ruby Shell. The commands to execute are:
root  TRuby::Exec("require '/usr/local/lib/root/libRuby'"); root  TRuby::Exec("c1 = TBrowser.new"); root  TRuby::Eval("c1.GetName"); root  TRuby::Eval("puts c1.GetName"); Browser root  TCanvas *c2 = new TCanvas("ruby test", "test", 10, 10, 100, 100); root  TRuby::Bind(c2, "$c"); root  TRuby::Eval("puts $c.GetTitle"); test root  TRuby::Prompt(); irb(main):001:0> print 1 1=> nil irb(main):002:0>
Notice that whenever you bind a ROOT Object in the Ruby side, you need to use a global Ruby variable, that is a variable with a leading "$".