On Jun 13, 2006, at 4:18 PM, Gregory Brown wrote:

> On 6/13/06, Eric Hodel <drbrain / segment7.net> wrote:
>
>> > Since the require "fastercsv" is within the DataSet.load method  
>> there
>> > is no reason why fastercsv should load at this point.
>>
>> Yes, there is.  ruport required it.
>
> Eric, I think you are missing something here.
> In ruby, if you put a require inside of a method, it is not required
> until that method is called.
>
> [sandal@harmonix ruport]$ irb --simple-prompt
>>> def foo; require "rubygems"; end
> => nil
>>> $LOADED_FEATURES.any? { |e| e =~ /rubygems/ }
> => false
>>> foo
> => true
>>> $LOADED_FEATURES.any? { |e| e =~ /rubygems/ }
> => true
>
>
> require "ruport" does NOT call require "fastercsv"

$ cat x.rb
deps = %w[
   /usr/local/lib/ruby/gems/1.8/gems/ruport-0.4.5/lib
   /usr/local/lib/ruby/gems/1.8/gems/pdf-writer-1.1.3/lib
   /usr/local/lib/ruby/gems/1.8/gems/transaction-simple-1.3.0/lib
   /usr/local/lib/ruby/gems/1.8/gems/color-tools-1.3.0/lib
]

deps.each { |d| $:.unshift d } # add paths manually outside rubygems

$" << 'rubygems.rb' # pretend we already required rubygems

require 'ruport' # raises an error, fastercsv not found

$ ruby x.rb
/usr/local/lib/ruby/gems/1.8/gems/ruport-0.4.5/lib/ruport/format/ 
plugin.rb:48:in `require': no such file to load -- fastercsv (LoadError)
         from /usr/local/lib/ruby/gems/1.8/gems/ruport-0.4.5/lib/ 
ruport/format/plugin.rb:48
         from /usr/local/lib/ruby/gems/1.8/gems/ruport-0.4.5/lib/ 
ruport/format.rb:73
         from /usr/local/lib/ruby/gems/1.8/gems/ruport-0.4.5/lib/ 
ruport/format.rb:72
         from /usr/local/lib/ruby/gems/1.8/gems/ruport-0.4.5/lib/ 
ruport.rb:60
         from /usr/local/lib/ruby/gems/1.8/gems/ruport-0.4.5/lib/ 
ruport.rb:59
         from x.rb:12
$ cat -n /usr/local/lib/ruby/gems/1.8/gems/ruport0.4.5/lib/ruport/ 
format/plugin.rb | grep -A3 -B3 48
     45
     46
     47      class CSVPlugin < Format::Plugin
     48        require "fastercsv"
     49
     50        format_field_names do
     51          FasterCSV.generate { |csv| csv << data.fields }
$ cat -n /usr/local/lib/ruby/gems/1.8/gems/ruport-0.4.5/lib/ruport.rb  
| grep -A3 -B3 60
     57
     58
     59  %w[config report format query data_row data_set].each { |lib|
     60    require "ruport/#{lib}"
     61  }

> Ruport::DataSet.load does

It may also, but it is not the only place.

-- 
Eric Hodel - drbrain / segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com