Ruby gems, and the require problem (was Re: RAA Status & b)

* ES <ruby-ml@magical-cat.org> [2005-03-05 03:08:03 +0900]:

Chad, why does Gems need to override #require (or provide #require_gem)?
I haven't been able to find a concise explanation and I'd rather not
poke around source code.

I'm not Chad, but...
it's because $: (aka $LOAD_PATH) does not contain the gem path.

ruby -e '$:.each { |i| p i }'
"<prefix>/lib/ruby/site_ruby/1.8"
"<prefix>/lib/ruby/site_ruby/1.8/powerpc-darwin7.7.0"
"<prefix>/lib/ruby/site_ruby"
"<prefix>/lib/ruby/1.8"
"<prefix>/lib/ruby/1.8/powerpc-darwin7.7.0"
"."

ls -alF <prefix>/lib/ruby/
total 0
drwxr-xr-x 5 jdf jdf 170 27 Dec 09:13 ./
drwxr-xr-x 7 jdf jdf 238 26 Dec 17:17 ../
drwxr-xr-x 129 jdf jdf 4386 9 Jan 00:56 1.8/
drwxr-xr-x 3 jdf jdf 102 27 Dec 09:13 gems/
drwxr-xr-x 6 jdf jdf 204 2 Jan 09:33 site_ruby/

Jim Freeze
Code Red. Code Ruby

Let's hope I can make it concise and clear :slight_smile:
....
   RubyGems allows you to install multiple versions of the same
library. In order to get Ruby to load the one you actually want at
runtime, it modifies the $LOAD_PATH. If we didn't do require_gem or
override require, you would have to set your $LOAD_PATH (or -I on the
command line) to include the library's installation directory, a la:

ruby -I /usr/local/lib/ruby/gems/1.8/gems/redcloth-3.0.0/lib myscript.rb

Does that explanation make sense?

···

On Sat, 5 Mar 2005 03:08:03 +0900, ES <ruby-ml@magical-cat.org> wrote:

Chad Fowler wrote:
> On Sat, 5 Mar 2005 00:43:45 +0900, Austin Ziegler <halostatue@gmail.com> wrote:
>
>>Ultimately, I agree with you. Ruby needs RubyGems in the core as a
>>replacement to require without doing 'require "rubygems"'. But it
>>does solve a very real problem, and it solves it reasonably well.
>>
>
>
> Well put. I think a lot of the fire would fade out of this debate if
> RubyGems were integrated into Ruby in such a way that it didn't
> require anything "special" to work. That has always been our hope and
> intent.

Chad, why does Gems need to override #require (or provide #require_gem)?
I haven't been able to find a concise explanation and I'd rather not
poke around source code.

--

Chad Fowler
http://chadfowler.com

http://rubygems.rubyforge.org (over 100,000 gems served!)

To further back up this point. Versioning is one of ruby gems killer features.

I use require_gem <name>, "=1.0.0" style version locking a lot in my
applications. I have a production web server which runs 5 different
rails applications like my typo weblog engine, hieraki demo
installation and my ecommerce store plus internal apps. Ruby gems
allows me to update and deploy one after another to the latest rails
because they all are locked against the gems for which I know the test
cases work.

···

Let's hope I can make it concise and clear :slight_smile:
....
   RubyGems allows you to install multiple versions of the same
library. In order to get Ruby to load the one you actually want at
runtime, it modifies the $LOAD_PATH. If we didn't do require_gem or
override require, you would have to set your $LOAD_PATH (or -I on the
command line) to include the library's installation directory, a la:

ruby -I /usr/local/lib/ruby/gems/1.8/gems/redcloth-3.0.0/lib myscript.rb

Does that explanation make sense?

Chad Fowler

--
Tobi
http://www.snowdevil.ca - Snowboards that don't suck
http://www.hieraki.org - Open source book authoring
http://blog.leetsoft.com - Technical weblog

Chad Fowler wrote:

Chad Fowler wrote:

Ultimately, I agree with you. Ruby needs RubyGems in the core as a
replacement to require without doing 'require "rubygems"'. But it
does solve a very real problem, and it solves it reasonably well.

Well put. I think a lot of the fire would fade out of this debate if
RubyGems were integrated into Ruby in such a way that it didn't
require anything "special" to work. That has always been our hope and
intent.

Chad, why does Gems need to override #require (or provide #require_gem)?
I haven't been able to find a concise explanation and I'd rather not
poke around source code.

Let's hope I can make it concise and clear :slight_smile: ....
   RubyGems allows you to install multiple versions of the same
library. In order to get Ruby to load the one you actually want at
runtime, it modifies the $LOAD_PATH. If we didn't do require_gem or
override require, you would have to set your $LOAD_PATH (or -I on the
command line) to include the library's installation directory, a la:

ruby -I /usr/local/lib/ruby/gems/1.8/gems/redcloth-3.0.0/lib myscript.rb

Does that explanation make sense?

Hm. So there are no cunning plans to take over all of the Rubyists'
computers and execute a remote installation of BeOS on them? Well,
that makes me feel a lot...sadder :confused: Damn you guys. Not even a little
cunning? Cunnette? Cunnino? Nanocunny? Er. You see where this is going.

Would it be, then, possible to implement a switch that would just append
the just-added directory to $LOAD_PATH (RUBYLIB)? It might be prudent,
I suppose, to actually create a separate tool to manage the path if it's
very large, to avoid duplication. If you won't do it immediately, then I
will. THAT'll teach you.

Of course, if Gems is at some point added to Ruby core to supplant,
supplement or even supplament the standard require mechanism, I'll
be all for it.

*starts singing the Rubynia national anthem*

*why, yes, it IS by Depeche Mode, why do you ask?*

> Chad Fowler

E

···

On Sat, 5 Mar 2005 03:08:03 +0900, ES <ruby-ml@magical-cat.org> wrote:

On Sat, 5 Mar 2005 00:43:45 +0900, Austin Ziegler <halostatue@gmail.com> wrote:

Hmm. What if require 'rubygems' just added the paths for the latest
version of all gems to $LOAD_PATH? Would that work? It's a bit of a
hack, but this is part of the trouble with RubyGems giving every
library and application its own directory.

Bill

···

On Sat, 5 Mar 2005 03:31:47 +0900, Chad Fowler <chadfowler@gmail.com> wrote:

On Sat, 5 Mar 2005 03:08:03 +0900, ES <ruby-ml@magical-cat.org> wrote:
> Chad Fowler wrote:
> > On Sat, 5 Mar 2005 00:43:45 +0900, Austin Ziegler <halostatue@gmail.com> wrote:
> >
> >>Ultimately, I agree with you. Ruby needs RubyGems in the core as a
> >>replacement to require without doing 'require "rubygems"'. But it
> >>does solve a very real problem, and it solves it reasonably well.
> >>
> >
> >
> > Well put. I think a lot of the fire would fade out of this debate if
> > RubyGems were integrated into Ruby in such a way that it didn't
> > require anything "special" to work. That has always been our hope and
> > intent.
>
> Chad, why does Gems need to override #require (or provide #require_gem)?
> I haven't been able to find a concise explanation and I'd rather not
> poke around source code.

Let's hope I can make it concise and clear :slight_smile:
....
   RubyGems allows you to install multiple versions of the same
library. In order to get Ruby to load the one you actually want at
runtime, it modifies the $LOAD_PATH. If we didn't do require_gem or
override require, you would have to set your $LOAD_PATH (or -I on the
command line) to include the library's installation directory, a la:

ruby -I /usr/local/lib/ruby/gems/1.8/gems/redcloth-3.0.0/lib myscript.rb

Does that explanation make sense?
--

Chad Fowler
http://chadfowler.com
http://rubycentral.org
http://rubygarden.org
http://rubygems.rubyforge.org (over 100,000 gems served!)

--
$stdout.sync = true
"Just another Ruby hacker.".each_byte do |b|
  ('a'..'z').step do|c|print c+"\b";sleep 0.007 end;print b.chr
end; print "\n"