Class: Module
- Inherits:
-
Object
- Object
- Module
- Defined in:
- lib/module_ext.rb
Overview
TDD helpers for modules.
Defined Under Namespace
Modules: Reloader
Class Method Summary collapse
-
.by_name(name) ⇒ Object
load a module by name.
Instance Method Summary collapse
-
#etest(test = nil) ⇒ Object
reloads the module, and runs the module’s etests.
-
#instances ⇒ Object
returns all instances of a module.
-
#reload ⇒ Object
tries to reload the source file for this module.
Class Method Details
Instance Method Details
#etest(test = nil) ⇒ Object
reloads the module, and runs the module’s etests.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/module_ext.rb', line 15 def etest(test = nil) reload if respond_to?(:reload) begin old_argv = Object.const_get "ARGV" Object.const_set "ARGV", [ "-n", test.to_s ] if test # hack! ::Etest.run self.const_get("Etest") ensure Object.const_set "ARGV", old_argv end end |
#instances ⇒ Object
returns all instances of a module
30 31 32 33 34 |
# File 'lib/module_ext.rb', line 30 def instances #:nodoc: r = [] ObjectSpace.each_object(self) { |mod| r << mod } r end |
#reload ⇒ Object
tries to reload the source file for this module. THIS IS A DEVELOPMENT helper, don’t try to use it in production mode!
Limitations:
To reload a module with a name of “X::Y” we try to load (in that order) “x/y.rb”, “x.rb”
56 57 58 59 60 61 |
# File 'lib/module_ext.rb', line 56 def reload Module::Reloader.reload_file("#{to_s.underscore}.rb") || begin dlog("Cannot reload module #{self}") false end end |