Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/module_ext.rb

Overview

TDD helpers for modules.

Defined Under Namespace

Modules: Reloader

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.by_name(name) ⇒ Object

load a module by name.



71
72
73
74
75
76
77
78
# File 'lib/module_ext.rb', line 71

def self.by_name(name)                                  #:nodoc:
  Kernel.silent do
    r = eval(name, nil, __FILE__, __LINE__)
    r if r.is_a?(Module) && r.name == name
  end
rescue NameError, LoadError
  nil
end

Instance Method Details

#etest(*args) ⇒ Object

reloads the module, and runs the module’s etests.



15
16
17
18
19
20
# File 'lib/module_ext.rb', line 15

def etest(*args)
  etests = const_get("Etest")
  modules = [ self, etests ]
  Reloader.reload *modules
  ::EtestUnit.run etests, *args
end

#instancesObject

returns all instances of a module



63
64
65
66
67
# File 'lib/module_ext.rb', line 63

def instances                                           #:nodoc:
  r = []
  ObjectSpace.each_object(self) { |mod| r << mod }
  r
end

#reloadObject



47
48
49
50
# File 'lib/module_ext.rb', line 47

def reload
  Reloader.reload(self)
  self
end

#source_filesObject



52
53
54
55
56
57
58
59
# File 'lib/module_ext.rb', line 52

def source_files
  public_instance_methods(false).
    map do |method_name| instance_method(method_name) end.
    map(&:source_location).compact.
    map(&:first).
    uniq.
    sort
end