# Odd Ruby/Rubygems/gem path problem

**URL:** <https://www.ruby-forum.com/t/odd-ruby-rubygems-gem-path-problem/166413>\
**Category:** Ruby\
**Created:** [April 24, 2009, 10:49pm UTC](https://www.ruby-forum.com/t/odd-ruby-rubygems-gem-path-problem/166413 "2009-04-24T22:49:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [April 24, 2009, 10:49pm UTC](https://www.ruby-forum.com/t/odd-ruby-rubygems-gem-path-problem/166413/1 "2009-04-24T22:49:01Z")

</div>

I’ve spent too much time trying to solve this little problem. I wonder  
if you can help:

I work on a Mac OS X Leopard. I recently started using a different  
account as my primary login. Things that shouldnt have, started  
breaking. I suspect permissions, file ownership etc problems. But  
check this out

# I am using shoulda as a random example gem, this example has nothing

# to do specifically with shoulda

# see that I do have shoulda installed:

$ gem which shoulda  
(checking gem thoughtbot-shoulda-2.10.1 for shoulda)  
/opt/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda.rb

# see that I have Ruby automatically searching for gems

$ echo $RUBYOPT  
rubygems

# see that my ruby install works for a trivial case

$ ruby -e “puts 1”  
1

# see that it refuses to see the shoulda gem from the command line

$ ruby -rshoulda -e “puts 1”  
ruby: no such file to load – shoulda (LoadError)  
$ ruby -rubygems -rshoulda -e “puts 1”  
ruby: no such file to load – shoulda (LoadError)  
$ ruby -rubygems -rshoulda -e “puts 1”

#see this trivial program:  
$ cat test1.rb  
require ‘rubygems’  
require ‘shoulda’  
puts `gem which shoulda`/mydev/graphicsplay

# does work as expected

$ ruby test1.rb  
(checking gem thoughtbot-shoulda-2.10.1 for shoulda)  
/opt/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda.rb  
/mydev/graphicsplay$

### Any ideas would be greatly appreciated. It’s probably something

stupid I am just missing it…

Thanks!

Pito

---

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [April 24, 2009, 11:37pm UTC](https://www.ruby-forum.com/t/odd-ruby-rubygems-gem-path-problem/166413/2 "2009-04-24T23:37:27Z")

</div>

On Apr 24, 2009, at 13:49, Pito S. wrote:

> # see that it refuses to see the shoulda gem from the command line
> 
> $ ruby -rshoulda -e “puts 1”  
> ruby: no such file to load – shoulda (LoadError)  
> $ ruby -rubygems -rshoulda -e “puts 1”  
> ruby: no such file to load – shoulda (LoadError)  
> $ ruby -rubygems -rshoulda -e “puts 1”

the -r command line option uses rb\_require() the C function, not  
Kernel#require the method. 1.9 does not have this limitation.

---

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [April 25, 2009, 2:37am UTC](https://www.ruby-forum.com/t/odd-ruby-rubygems-gem-path-problem/166413/3 "2009-04-25T02:37:51Z")

</div>

Eric H. wrote:

> On Apr 24, 2009, at 13:49, Pito S. wrote:
> 
> > # see that it refuses to see the shoulda gem from the command line
> > 
> > $ ruby -rshoulda -e “puts 1”  
> > ruby: no such file to load – shoulda (LoadError)  
> > $ ruby -rubygems -rshoulda -e “puts 1”  
> > ruby: no such file to load – shoulda (LoadError)  
> > $ ruby -rubygems -rshoulda -e “puts 1”
> 
> the -r command line option uses rb\_require() the C function, not  
> Kernel#require the method. 1.9 does not have this limitation.

Eric, thanks. I am not sure of the implication of that. Are you saying  
therefore that one cannot rely on -rrubygems -rshoulda to work?

- Pito

---

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [April 25, 2009, 2:58am UTC](https://www.ruby-forum.com/t/odd-ruby-rubygems-gem-path-problem/166413/4 "2009-04-25T02:58:38Z")

</div>

On Apr 24, 2009, at 17:38, Pito S. wrote:

> > the -r command line option uses rb\_require() the C function, not  
> > Kernel#require the method. 1.9 does not have this limitation.
> 
> Eric, thanks. I am not sure of the implication of that. Are you saying  
> therefore that one cannot rely on -rrubygems -rshoulda to work?

With ruby 1.8, no. There is a workaround though:

ruby -rubygems -e ‘require “shoulda”; …’

---

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [April 26, 2009, 3:12pm UTC](https://www.ruby-forum.com/t/odd-ruby-rubygems-gem-path-problem/166413/5 "2009-04-26T15:12:33Z")

</div>

Pito S. schrieb:

> Another slight confusion: I’ve read about -rubygems as well as putting  
> -Cdirectory cd to directory, before executing your script  
> -n assume ‘while gets(); … end’ loop around your script  
> -x[directory] strip off text before #!ruby line and perhaps cd to
> 
> At this point I am just confused and curious about what’s going on.  
> What’s up with that -rubygems switch?  
> in fact it’s just the -r switch with ubygems to load  
> I have the ubygems.rb in /usr/lib/ruby/site\_ruby/1.8/  
> and the first line says:

# This file allows for the running of rubygems with a nice

# command line look-and-feel: ruby -rubygems foo.rb

all code it contains is:  
require ‘rubygems’

---

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [April 26, 2009, 4:01am UTC](https://www.ruby-forum.com/t/odd-ruby-rubygems-gem-path-problem/166413/6 "2009-04-26T04:01:21Z")

</div>

On Friday 24 April 2009 16:34:47 Eric H. wrote:

> the -r command line option uses rb\_require() the C function, not  
> Kernel#require the method. 1.9 does not have this limitation.

However, 1.9’s Kernel#autoload does seem to have that very limitation.

Worse, I cannot figure out how to duplicate autoload in pure Ruby, at  
least on  
1.9. I could do it in Rubinius, I think.

Is there a reason for this? Should I file a bug?

---

<div class="post-metadata">

**Author:** ![pitosalas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a4c791/32.png) [@pitosalas](https://www.ruby-forum.com/u/pitosalas)\
**Post date:** [April 26, 2009, 3:09pm UTC](https://www.ruby-forum.com/t/odd-ruby-rubygems-gem-path-problem/166413/7 "2009-04-26T15:09:38Z")

</div>

Eric H. wrote:

> On Apr 24, 2009, at 17:38, Pito S. wrote:
> 
> > > the -r command line option uses rb\_require() the C function, not  
> > > Kernel#require the method. 1.9 does not have this limitation.
> > 
> > Eric, thanks. I am not sure of the implication of that. Are you saying  
> > therefore that one cannot rely on -rrubygems -rshoulda to work?
> 
> With ruby 1.8, no. There is a workaround though:
> 
> ruby -rubygems -e ‘require “shoulda”; …’

Another slight confusion: I’ve read about -rubygems as well as putting  
“rubygems” into RUBY\_OPT in a document about gems.

But, in fact if I do a man ruby or a ruby --help there’s no mention of  
the -rubygems option:

$ruby --h  
Usage: ruby [switches] [–] [programfile] [arguments]  
-0[octal] specify record separator (\0, if no argument)  
-a autosplit mode with -n or -p (splits $\_ into $F)  
-c check syntax only  
-Cdirectory cd to directory, before executing your script  
-d set debugging flags (set $DEBUG to true)  
-e ‘command’ one line of script. Several -e’s allowed. Omit  
[programfile]  
-Fpattern split() pattern for autosplit (-a)  
-i[extension] edit ARGV files in place (make backup if extension  
supplied)  
-Idirectory specify $LOAD\_PATH directory (may be used more than  
once)  
-Kkcode specifies KANJI (Japanese) code-set  
-l enable line ending processing  
-n assume ‘while gets(); … end’ loop around your script  
-p assume loop like -n but print line also like sed  
-rlibrary require the library, before executing your script  
-s enable some switch parsing for switches after script  
name  
-S look for the script using PATH environment variable  
-T[level] turn on tainting checks  
-v print version number, then turn on verbose mode  
-w turn warnings on for your script  
-W[level] set warning level; 0=silence, 1=medium, 2=verbose  
(default)  
-x[directory] strip off text before #!ruby line and perhaps cd to  
directory  
–copyright print the copyright  
–version print the version

$ ruby -v  
ruby 1.8.7 (2009-04-08 patchlevel 160) [powerpc-darwin9]

By the way, my ruby install is via port, in case that matters.  
$ which ruby  
/opt/local/bin/ruby

At this point I am just confused and curious about what’s going on.  
What’s up with that -rubygems switch?
