Module: RubyImport

Defined in:
lib/ruby_import.rb,
lib/ruby_import/version.rb

Overview

frozen_string_literal: true

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
'0.2.0'
@@imported_files =
{}

Instance Method Summary collapse

Instance Method Details

#import(file) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ruby_import.rb', line 14

def import(file)
  if file.is_a? Module
    defined_module = file
  else
    file += '.rb' unless file.end_with? '.rb'
    file = prepare_file file
    defined_module = @@imported_files[file]
    @@imported_files[file] = defined_module = require_module file unless defined_module

    defined_module = Object.const_get defined_module
  end
  Class.new { include defined_module }.new.freeze
end