|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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.zenunit.com/ 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 > |
|
![]() |
| Outils de la discussion | |
|
|