Module: WrapInModule::Script::LoadInModuleMethods

Defined in:
lib/wrap_in_module.rb

Instance Method Summary collapse

Instance Method Details

#load_in_module(__file__) ⇒ Object

Loads file in this module’s context. Note that __FILE__ and __LINE__ work correctly in file. Called by #load and #require; not normally called directly.



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/wrap_in_module.rb', line 52

def load_in_module(__file__)
  module_eval("@__script_scope ||= binding\n" + IO.read(__file__),
    File.expand_path(__file__), 0)
    # start numbering at 0 because of the extra line.
    # The extra line does nothing in sub-script files.
rescue Errno::ENOENT
  if /#{__file__}$/ =~ $!.message # No extra locals in this scope.
    raise MissingFile, $!.message
  else
    raise
  end
end