# Command line rubygems and require

**URL:** <https://www.ruby-forum.com/t/command-line-rubygems-and-require/60095>\
**Category:** Ruby\
**Created:** [May 10, 2006, 5:54am UTC](https://www.ruby-forum.com/t/command-line-rubygems-and-require/60095 "2006-05-10T05:54:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![polypus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b5ac83/32.png) [@polypus](https://www.ruby-forum.com/u/polypus)\
**Post date:** [May 10, 2006, 5:54am UTC](https://www.ruby-forum.com/t/command-line-rubygems-and-require/60095/1 "2006-05-10T05:54:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![polypus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b5ac83/32.png) [@polypus](https://www.ruby-forum.com/u/polypus)\
**Post date:** [May 10, 2006, 6:03am UTC](https://www.ruby-forum.com/t/command-line-rubygems-and-require/60095/2 "2006-05-10T06:03:28Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![polypus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b5ac83/32.png) [@polypus](https://www.ruby-forum.com/u/polypus)\
**Post date:** [May 10, 2006, 6:06am UTC](https://www.ruby-forum.com/t/command-line-rubygems-and-require/60095/3 "2006-05-10T06:06:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![polypus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b5ac83/32.png) [@polypus](https://www.ruby-forum.com/u/polypus)\
**Post date:** [May 10, 2006, 6:08am UTC](https://www.ruby-forum.com/t/command-line-rubygems-and-require/60095/4 "2006-05-10T06:08:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![polypus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b5ac83/32.png) [@polypus](https://www.ruby-forum.com/u/polypus)\
**Post date:** [May 10, 2006, 3:40pm UTC](https://www.ruby-forum.com/t/command-line-rubygems-and-require/60095/5 "2006-05-10T15:40:40Z")

</div>

> > examples directory which goes something like:
> 
> You could do
> 
> ruby -rubygems -e ‘require ‘foo’; load(ARGV.shift)’ requires\_foo2.rb

thanks guys
