Class: Peruby::ModuleDefinition
- Inherits:
-
Object
- Object
- Peruby::ModuleDefinition
- Defined in:
- lib/peruby/runtime/module_loader.rb
Overview
Definition collected by Peruby.define_module's small Ruby DSL.
Instance Attribute Summary collapse
-
#exports ⇒ Object
readonly
Returns the value of attribute exports.
-
#functions ⇒ Object
readonly
Returns the value of attribute functions.
Instance Method Summary collapse
- #export_ok(*names) ⇒ Object
-
#initialize ⇒ ModuleDefinition
constructor
A new instance of ModuleDefinition.
- #install(name, runtime) ⇒ Object
- #sub(name, proto: nil, &implementation) ⇒ Object
Constructor Details
#initialize ⇒ ModuleDefinition
Returns a new instance of ModuleDefinition.
9 10 11 12 |
# File 'lib/peruby/runtime/module_loader.rb', line 9 def initialize @exports = [] @functions = {} end |
Instance Attribute Details
#exports ⇒ Object (readonly)
Returns the value of attribute exports.
7 8 9 |
# File 'lib/peruby/runtime/module_loader.rb', line 7 def exports @exports end |
#functions ⇒ Object (readonly)
Returns the value of attribute functions.
7 8 9 |
# File 'lib/peruby/runtime/module_loader.rb', line 7 def functions @functions end |
Instance Method Details
#export_ok(*names) ⇒ Object
14 |
# File 'lib/peruby/runtime/module_loader.rb', line 14 def export_ok(*names) = @exports.concat(names.map(&:to_s)) |
#install(name, runtime) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/peruby/runtime/module_loader.rb', line 20 def install(name, runtime) @functions.each do |sub_name, (prototype, implementation)| code = Code.new("#{name}::#{sub_name}", NativeBody.new(&implementation), runtime.env, name, prototype) runtime.stash.glob(code.name).code = code end runtime.stash.touch end |
#sub(name, proto: nil, &implementation) ⇒ Object
16 17 18 |
# File 'lib/peruby/runtime/module_loader.rb', line 16 def sub(name, proto: nil, &implementation) @functions[name.to_s] = [proto, implementation] end |