Class: CommonJS::Module

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

Defined Under Namespace

Classes: Native

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, env) ⇒ Module

Returns a new instance of Module.



7
8
9
10
11
12
# File 'lib/commonjs/module.rb', line 7

def initialize(id, env)
  @id = id
  @env = env
  @exports = env.new_object
  @segments = id.split('/')
end

Instance Attribute Details

#exportsObject

Returns the value of attribute exports.



5
6
7
# File 'lib/commonjs/module.rb', line 5

def exports
  @exports
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/commonjs/module.rb', line 4

def id
  @id
end

Instance Method Details

#require_functionObject



14
15
16
17
18
19
20
# File 'lib/commonjs/module.rb', line 14

def require_function
  @require_function ||= lambda do |*args|
    this, module_id = *args
    module_id ||= this #backwards compatibility with TRR < 0.10
    @env.require(expand(module_id))
  end
end