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.
Bbc4b3fca1ae3161257a8636145b424d?d=identicon&s=25 Elliot Temple (Guest)
on 2006-06-04 20: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 Temple
http://www.curi.us/blog/
3afd3e5e05dc9310c89aa5762cc8dd1d?d=identicon&s=25 Timothy Hunter (Guest)
on 2006-06-04 20:42
(Received via mailing list)
Elliot Temple wrote:
> curi-g5:/usr/local/lib/ruby/site_ruby/myrubylib curi$ ls
>
>
> -- Elliot Temple
> 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
9358cc96c46055cd68d4a76a9aefe026?d=identicon&s=25 Daniel Harple (Guest)
on 2006-06-04 20:48
(Received via mailing list)
On Jun 4, 2006, at 8:35 PM, Elliot Temple 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
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2006-06-04 21:47
(Received via mailing list)
On Jun 4, 2006, at 20:35, Elliot Temple 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.