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:
root [0] gSystem>Load("libRuby");
root [1] TRuby::Exec("require '/usr/local/lib/root/libRuby'");
root [2] TRuby::Exec("c1 = TBrowser.new");
root [3] TRuby::Eval("c1.GetName");
root [4] TRuby::Eval("puts c1.GetName");
Browser
root [5] TCanvas *c2 = new TCanvas("ruby test", "test", 10, 10, 100, 100);
root [6] TRuby::Bind(c2, "$c");
root [7] TRuby::Eval("puts $c.GetTitle");
test
root [8] TRuby::Prompt();
root [9] 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 "$".