Command line rubygems and require

given the file requires_foo.rb

require ‘foo’

class ReqFoo
end

if foo is a gem, then i can run it by going:

ruby -rubygems requires_foo.rb

why can’t i have a file requires_foo2.rb

class ReqFoo
end

and go:

ruby -rubygems -r foo requires_foo2.rb

it’s giving me a LoadError

but maybe i’m approaching the problem wrong. what i’m doing is that i
have a large file which is a tutorial to my lib in rdoc, and which is
doing an :include: of my examples when need be, in order for my example
code to be writen in only one place. the problem is that i don’t want a
whole lot of requires and shebangs and whatnot in the examples. is there
a standard proceedure for this kind of thing? ideas/suggestions for an
rdoc noob? my solution is just to have a little shell script in the
examples directory which goes something like:

ruby -rubygems -r foo example$1.rb

but then there’s the problem listed above.

thanks,
_c

my solution is just to have a little shell script in the
examples directory which goes something like:

ok i’ve rewritten my little shell script in ruby solving my main
problem, but am still curious about the command line procedure.

polypus wrote:

why can’t i have a file requires_foo2.rb

class ReqFoo
end

and go:

ruby -rubygems -r foo requires_foo2.rb

RubyGems wraps the require command in order to locate the gem
directories during a require. The -r option bypasses the require
command entirely and attempts to load the file without allowing RubyGems
to do its thang.

Sorry.

– Jim W.

On May 9, 2006, at 11:54 PM, polypus wrote:

examples directory which goes something like:

You could do

ruby -rubygems -e ‘require ‘foo’; load(ARGV.shift)’ requires_foo2.rb

examples directory which goes something like:

You could do

ruby -rubygems -e ‘require ‘foo’; load(ARGV.shift)’ requires_foo2.rb

thanks guys