Changes between Initial Version and Version 1 of WikiStart/Ruby/LocalRubyLoading


Ignore:
Timestamp:
08/15/11 17:49:02 (8 years ago)
Author:
sylvain.joyeux
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WikiStart/Ruby/LocalRubyLoading

    v1 v1  
     1This page explains how to add example/test scripts in Ruby packages, so that the Ruby package does not have to be in RUBYLIB 
     2 
     3== Situation == 
     4 
     5You have [http://rock.opendfki.de/wiki/WikiStart/Standards/RG5 a ruby package] and want to add an example script (for instance in an examples/ directory). So, your package layout is like: 
     6 
     7 - lib/: the code 
     8 - examples/: the example scripts 
     9 
     10What you want is to be able to run the example scripts without having to add the lib/ directory to RUBYLIB (i.e. run the script after a fresh checkout for instance) 
     11 
     12== Code == 
     13 
     14The following pattern can be used at the top of the script: 
     15 
     16{{{ 
     17$LOAD_PATH.unshift File.expand_path(File.join('..', 'lib'), File.dirname(__FILE__)) 
     18}}} 
     19 
     20This adds, inside the script, the lib/ directory in Ruby's search path, and makes sure that it gets a higher precedence than global files