Forum: Ruby help with require, symlinks

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Elliot T. (Guest)
on 2006-06-04 22:36
(Received via mailing list)
I'm on OS X 10.4.6

i want to be able to require my files without the full path. i want
to keep them in my home directory so i don't lose them. i tried:

sudo ln -s /Users/curi/me/rubylib /usr/local/lib/ruby/site_ruby/
myrubylib

it made the link. observe:

curi-g5:/usr/local/lib/ruby/site_ruby curi$ cd myrubylib
curi-g5:/usr/local/lib/ruby/site_ruby/myrubylib curi$ ls
curi.rb

however:

require "curi" # can't find the file

require "/Users/curi/me/rubylib/curi" # this works
require "/usr/local/lib/ruby/site_ruby/myrubylib/curi" # this works too

not sure what i'm doing wrong or how to do this properly..

BTW:

curi-g5:/usr/local/lib/ruby/site_ruby curi$ ruby -e "puts $:"
/usr/local/lib/ruby/site_ruby/1.8
/usr/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.5.0
/usr/local/lib/ruby/site_ruby
/usr/local/lib/ruby/1.8
/usr/local/lib/ruby/1.8/powerpc-darwin8.5.0
.


-- Elliot T.
http://www.curi.us/blog/
Timothy H. (Guest)
on 2006-06-04 22:42
(Received via mailing list)
Elliot T. wrote:
> curi-g5:/usr/local/lib/ruby/site_ruby/myrubylib curi$ ls
>
>
> -- Elliot T.
> http://www.curi.us/blog/
>
>
>
>
Might it be simpler for you to just add your home directory to Ruby's
search path by using the RUBYLIB environment variable?

export RUBYLIB=/Users/curi/me/rubylib
Daniel H. (Guest)
on 2006-06-04 22:48
(Received via mailing list)
On Jun 4, 2006, at 8:35 PM, Elliot T. wrote:

> I'm on OS X 10.4.6
>
> i want to be able to require my files without the full path. i want
> to keep them in my home directory so i don't lose them.

Try this:

# .profile/.bash_profile/.whatever

export RUBYLIB="$HOME/to/your/files

Straight out of Ruby's man page.

$ man ruby

-- Daniel
Xavier N. (Guest)
on 2006-06-04 23:47
(Received via mailing list)
On Jun 4, 2006, at 20:35, Elliot T. wrote:

> I'm on OS X 10.4.6
>
> i want to be able to require my files without the full path. i want
> to keep them in my home directory so i don't lose them. i tried:
>
> sudo ln -s /Users/curi/me/rubylib /usr/local/lib/ruby/site_ruby/
> myrubylib

<snip>

> require "curi" # can't find the file

Others have already mentioned RUBYLIB, but let me note that the very
myrubylib under site_ruby is *not* in $:. Thus, you'd need to specify
the parent directoy as well:

   require 'myrubylib/curi'

You load the core library smtp.rb as 'net/smtp' because of the same
reason, smtp.rb lives in

   /usr/local/lib/ruby/1.8/net/smtp.rb

and the directory in the load path there is /usr/local/lib/ruby/1.8.

RUBYLIB is the canonical solution to that, but at least you know why
your test is not working.

-- fxn
This topic is locked and can not be replied to.