Robert Klemme wrote:
> 
> "require" is for loading library code (libs as parts of the
> installation, self written libs as well as gems).
> 
> "load" is for explicitly forcing a file load and execution at a define
> place in the source code.

Thanks for the clarification Robert and I like your distinction because 
it makes more sense to me.  With your example in place, I am using 
require and load statements correctly then. The only thing I've been 
doing with regard to load statements is defining an absolute load path 
rather than a relative load path.  Code execution in this example is the 
loading of an xml source file (xrc) by wx_sugar.

> Now, I don't know Ocra and hence I can't say anything about it.  My
> approach is this: I have environment variable RUBYLIB set to an
> absolute path where I place my own written libs ("${HOME}/lib/ruby" in
> my case).  I don't have any gems installed on the system I am working
> on so no requirements there.  But generally the usage model of
> "require" is that there is a list of entry points (partly built into
> the interpreter, partly provided by the user e.g. via $RUBYLIB) which
> are searched - which also means you generally use only relative paths
> with require.  This is also true for recursive requires - which can be
> autoloads as well.  See here for an example:

This is strange because I don't know why I never thought about doing 
this with Ruby.  I'm so used to keeping my projects separate and 
therefore, I tend to keep the libs separate.  However, I could see 
defining a libs dir for reusable library classes that I require in 
future projects.  Then, all I would have to do is require and/or include 
the code I need.  Ocra does look over the rubyopt variables set at the 
time of processing.  I'll have to check the $: to see that my custom lib 
directories are being set properly and included, but I can definitely 
see this being a better way of implementing things later on.  I can 
privatize and store all my libs on github for safekeeping and rdoc 
everything for my own benefit.

Robert this actually helps me out a lot because I want to write my own 
custom modules for use with wxruby and I can define the namespaces and 
just extend off those modules through dialogblocks when I generate my 
elements and xrc source.

> 
> http://github.com/rklemme/muppet-laboratories/blob/master/lib/animal.rb
>

I have not looked into autoloads at all.  I'll read up on them.

> Turning back to your original example: it looks like what you really
> want is to do "require 'ui'" and have a file "ui.rb" located somewhere
> in your library path which then consists mainly (or only) of "require
> 'ui/a'" lines. "a.rb" then would be placed in directory <lib>/ui, i.e.
> below the directory which contains file "ui.rb".

No, that's not what the issue was in this case.  The ui.rb file is 
actually a file called xrcframemain.rb which is automatically generated 
by xrcise.  This is one file that will always change in any application 
that is created.  So, it's a roaming ruby file depending on which 
project I'm in.  Inside of this file, there is a custom xml.load 
statement being used by wx_sugar to read xml source from an xrc file 
that's generated by most GUI designer apps.  This xml file contains 
information pertaining to GUI element positioning and also ties IDs to 
instance variables that will be used in the app, as well as sub-class 
element tags that are used to extend into modules.  So, together, the 
xrcframemain.rb and the ui.xrc files combine into a separate but usable 
structure where program code is kept separate from design code.

So, I won't change the requires for this particular file.  At the 
moment, I'm not having issues with any of my requires.  Everything is 
working well.  However, with your input and suggestions, I am going to 
change my whole way of thinking in terms of consolidating lib files for 
use with wxruby.

> 
> Hope that helps.
> 
> Kind regards
> 
> robert

It does - my thanks!

-- 
Posted via http://www.ruby-forum.com/.