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].
To work with the Ruby module, the LD_LIBRARY_PATH [PATH] and RUBYLIB need to be set in addition to the standard ROOTSYS.
export LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH export RUBYLIB=$ROOTSYS/lib:$RUBYLIB
set PATH=%ROOTSYS%/bin;%PATH% set RUBYLIB=%ROOTSYS%/bin;%RUBYLIB%
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:
Another way is to start the Ruby script with the Ruby require command:ruby -rlibRuby foo.rb
An example is as follows:require 'libRuby'
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
A ROOT user can run any Ruby command and eventually to run IRB, the Interactive Ruby Shell. The commands to execute are:
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 "$".root  gSystem>Load("libRuby"); 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(); root  TRuby::Prompt(); irb(main):001:0> print 1 1=> nil irb(main):002:0>