[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Testing a library, how to auto, autoload

goodieboy

4/2/2008 2:35:00 PM

Hi,

I'm writing some tests for a library, and don't want to "require"
every single module/class. Anyone know if a quick way to set autoload
for all modules/classes for library?

Matt

3 Answers

Phlip

4/2/2008 4:04:00 PM

0

goodieboy wrote:
> Hi,
>
> I'm writing some tests for a library, and don't want to "require"
> every single module/class. Anyone know if a quick way to set autoload
> for all modules/classes for library?

Autoload is a Rails feature, and it's not strictly recommendable.

So the question turns to - why are your modules and classes hard to require? Do
you have a balanced set of .rb files, where each one requires the things it
uses? Can't you just pull all class of a module in with one top-level require?

--
Phlip

Joel VanderWerf

4/2/2008 5:22:00 PM

0

goodieboy wrote:
> Hi,
>
> I'm writing some tests for a library, and don't want to "require"
> every single module/class. Anyone know if a quick way to set autoload
> for all modules/classes for library?

If you have some way of recognizing the names of your classes (such as a
regex), you could adapt the following:

if false
autoload :FileUtils, "fileutils"
else
class << Object
alias old_const_missing const_missing
def const_missing name
case name.to_sym
when :FileUtils; require "fileutils"; FileUtils
else
old_const_missing name
end
end
end
end

class A
def foo
p FileUtils
end
end

A.new.foo


--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Julian Leviston

4/3/2008 2:41:00 AM

0

Grab the contents of the folder, then loop through requiring them all.

Julian.


Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO
(#2) OUT NOW!
http://sensei.ze...


On 03/04/2008, at 1:34 AM, goodieboy wrote:

> Hi,
>
> I'm writing some tests for a library, and don't want to "require"
> every single module/class. Anyone know if a quick way to set autoload
> for all modules/classes for library?
>
> Matt
>