'require' and installing / using new libraries

I just downloaded Foxtails (the FXRuby extensions), and upon running the
install scripts I was surprised to see that a bunch of the ruby files that
came with it had been copied over into my ruby/lib/site_ruby/1.8 directory.

Is there a reason why installing libraries needs to make changes to the
directory in which ruby itself is installed? I would have expected the
installation to instead make additions to the path in $: instead.

How does ‘require’, $:, and installation of new libraries work? (Hyperlink
welcome; I did not find what I needed in pickaxe).

Thanks …

Its Me wrote:

I just downloaded Foxtails (the FXRuby extensions), and upon running the
install scripts I was surprised to see that a bunch of the ruby files that
came with it had been copied over into my ruby/lib/site_ruby/1.8 directory.

The installer in foxtails is the standard one, used by many packages:

http://raa.ruby-lang.org/list.rhtml?name=setup

You can install to another directory by doing

$ ruby install.rb config --prefix=/my/home/dir
$ ruby install.rb setup
$ ruby install.rb install

It’s also possible to control the lib dir directly. See ‘ruby install.rb
–help’ for details on the --site-ruby option. Then you may need to
manually change your RUBYLIB env var.

Is there a reason why installing libraries needs to make changes to the
directory in which ruby itself is installed? I would have expected the
installation to instead make additions to the path in $: instead.

The site_ruby dir is, as I understand it, the place where non-standard
libraries are supposed to go.

What I do locally on my development machine is a bit different, because
I don’t like edit…install…edit…install. I have a lib dir in my home.
This dir is listed on my RUBYLIB, and I symlink from it to my various
project directories. This way, require finds my development code before
looking in the ruby/lib areas, but I don’t have to add each project
individually to RUBYLIB.

How does ‘require’, $:, and installation of new libraries work? (Hyperlink
welcome; I did not find what I needed in pickaxe).

What about “Ruby and Its World” in the pickaxe, does that help?

Btw, hope you like foxtails…

How does ‘require’, $:, and installation of new libraries work?
(Hyperlink
welcome; I did not find what I needed in pickaxe).

What about “Ruby and Its World” in the pickaxe, does that help?

Yes, thanks. I had missed that.

I can see some problems with how ‘require’ works (e.g. how do I refer to a
relative path from current working directory?), and recall seeing some
postings to fix it. A quick search did not uncover it. Any pointers?

Btw, hope you like foxtails…

Clean, simple, … undocumented :slight_smile: Seriously, I love it.

I’d also vote for your Observer to go into the standard Ruby libs, but I
don’t know how that works.

···

“Joel VanderWerf” vjoel@PATH.Berkeley.EDU wrote

Its Me wrote:

I can see some problems with how ‘require’ works (e.g. how do I refer to a
relative path from current working directory?), and recall seeing some
postings to fix it. A quick search did not uncover it. Any pointers?

Normally, ‘.’ is on the require path, $:. But that does not help if you
want to require relative to the current file being parsed by ruby,
rather than the current dir. There has been some discussion of this.
Search the ruby-talk archives for require_local.

Btw, hope you like foxtails…

Clean, simple, … undocumented :slight_smile: Seriously, I love it.

Yeah, gotta write docs…

I’d also vote for your Observer to go into the standard Ruby libs, but I
don’t know how that works.

Thanks, but I don’t think it’s widely used. One problem is that it
defines a module called Observable, and there is a standard library,
observer.rb, that also defines an module called Observable. I should
probably rename my module to ObservableAttribute, which is more precise,
anyway. Another problem is that overusing it can lead to code that is
very hard to debug (like a “come from” statement). It seems to work
nicely for wiring up GUI’s, though.