As pointed out by Matthew the second solution does not work on OS X
(or perhaps pre-1.8.7).
While trying to cope reasonably well with Rubygems I introduced some
problems which make the solution nonportable.
First I stumbled upon start_with? which is a String method only
available in 1.8.7. I recall implementing workarounds with regexps
quite a few times so I was like "Hell, why did I never use that?", and
the reason is it does not exist. Packaging 1.8.7 as the default Ruby
interpreter is evil ![]()
Second, there is an interesting problem with Rubygems: at one point
the class/module Gem exists but Gem.path does not. I did not see this
situation happen on the 1.8.7 Linux interpreter but it happens on
1.8.6 OS X.
Also there is a small bug with detecting the gem path. I thought
File.split splits to components bu it only splits to dirname and
basename.
So here goes the corrected solution which should again work on
multiple platforms.
It also removes some of the noise from the reported gem dependencies.
$ ruby -r q175.rb q175t.rb
require: q175t.rb:2: date => /sw/lib/ruby/1.8/date.rb
require: q175t.rb:3: readline => /sw/lib/ruby/1.8/i686-darwin/readline.bundle
require: q175t.rb:4: matrix => /sw/lib/ruby/1.8/matrix.rb
require: q175t.rb:5: rubygems => /sw/lib/ruby/1.8/rubygems.rb
require: q175t.rb:6: time => /sw/lib/ruby/1.8/time.rb
require: q175t.rb:7: hpricot =>
/sw/var/lib/gems/1.8/gems/hpricot-0.6.161/lib/hpricot.rb
require: q175t.rb:8: rubyforge =>
/sw/var/lib/gems/1.8/gems/rubyforge-1.0.0/lib/rubyforge.rb
require: /sw/var/lib/gems/1.8/gems/hoe-1.7.0/lib/hoe.rb:4: rake =>
/sw/var/lib/gems/1.8/gems/rake-0.8.1/lib/rake.rb
require: /sw/var/lib/gems/1.8/gems/hoe-1.7.0/lib/hoe.rb:5:
rake/gempackagetask =>
/sw/var/lib/gems/1.8/gems/rake-0.8.1/lib/rake/gempackagetask.rb
require: /sw/var/lib/gems/1.8/gems/hoe-1.7.0/lib/hoe.rb:6:
rake/rdoctask =>
/sw/var/lib/gems/1.8/gems/rake-0.8.1/lib/rake/rdoctask.rb
require: /sw/var/lib/gems/1.8/gems/hoe-1.7.0/lib/hoe.rb:7:
rake/testtask =>
/sw/var/lib/gems/1.8/gems/rake-0.8.1/lib/rake/testtask.rb
require: q175t.rb:9: hoe => /sw/var/lib/gems/1.8/gems/hoe-1.7.0/lib/hoe.rb
require: q175t.rb:10: curses => /sw/lib/ruby/1.8/i686-darwin/curses.bundle
Thanks
Michal
q175.rb (2.97 KB)
···
On 03/09/2008, Michal Suchanek <hramrach@centrum.cz> wrote:
$ cat q175t.rb
require 'date'
require 'readline'
require 'matrix'
require 'rubygems'
require 'time'
require 'hpricot'
require 'rubyforge'
require 'hoe'
require 'curses'