Class: Amrita2::Core::CodeGenerator::CGModule
- Defined in:
- lib/amrita2/template.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#constants ⇒ Object
readonly
Returns the value of attribute constants.
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #define_constant(const_def) ⇒ Object
- #define_method(vars, &block) ⇒ Object
- #end_of_module(cg) ⇒ Object
-
#initialize(name) ⇒ CGModule
constructor
A new instance of CGModule.
Constructor Details
#initialize(name) ⇒ CGModule
Returns a new instance of CGModule.
579 580 581 582 583 |
# File 'lib/amrita2/template.rb', line 579 def initialize(name) @name = name @constants = [] @methods = [] end |
Instance Attribute Details
#constants ⇒ Object (readonly)
Returns the value of attribute constants.
576 577 578 |
# File 'lib/amrita2/template.rb', line 576 def constants @constants end |
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
577 578 579 |
# File 'lib/amrita2/template.rb', line 577 def methods @methods end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
575 576 577 |
# File 'lib/amrita2/template.rb', line 575 def name @name end |
Instance Method Details
#define_constant(const_def) ⇒ Object
585 586 587 588 589 590 591 592 593 594 595 596 597 598 |
# File 'lib/amrita2/template.rb', line 585 def define_constant(const_def) name = nil @constants.each do |n, cdef| if cdef == const_def name = n break end end unless name name = "C#{sprintf("%03d", @constants.size)}" @constants << [name, const_def] end name end |
#define_method(vars, &block) ⇒ Object
600 601 602 603 604 |
# File 'lib/amrita2/template.rb', line 600 def define_method(vars, &block) name = "m#{sprintf("%03d", @methods.size)}" @methods << [name, vars, block] name end |
#end_of_module(cg) ⇒ Object
606 607 608 609 610 611 612 613 614 615 |
# File 'lib/amrita2/template.rb', line 606 def end_of_module(cg) @constants.each do |name, defs| cg.code("#{name} = #{defs}") end @methods.each do |name, vars, body| cg.define_method(name, vars) do body.call end end end |