Top Level Namespace

Defined Under Namespace

Modules: ApplicationHelper, CoreHelper Classes: Bones, Object, String

Instance Method Summary collapse

Instance Method Details

#force_load(map = {}) ⇒ Object

Loads filename, removing the associated class if defined

Arguments:

hash of 'Class' => 'filename' pairs

Example:

force_load 'Application' => 'application.rb'

will remove the Application class if found, and then load the application.rb file



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bones/extensions.rb', line 28

def force_load(map={})
  map.each do |klass, filename|
    if defined?(klass.name)
      basename = klass.to_s.split("::").last
      parent = klass.parent
      
      # Skip this class if it does not match the current one bound to this name
      next unless parent.const_defined?(basename) && klass = parent.const_get(basename)

      parent.instance_eval { remove_const basename } unless parent == klass
    end

    load filename 
  end
end